From ab25b104cd16656ee00edce00b02ca6b9cce4e10 Mon Sep 17 00:00:00 2001 From: oroberts Date: Fri, 25 Nov 2022 14:28:12 +0100 Subject: [PATCH 1/6] Closed day00 --- module00/subject/en.subject.tex | 526 ++++++++++++++++---------------- 1 file changed, 263 insertions(+), 263 deletions(-) diff --git a/module00/subject/en.subject.tex b/module00/subject/en.subject.tex index a4fd8a5e..2c0899e7 100644 --- a/module00/subject/en.subject.tex +++ b/module00/subject/en.subject.tex @@ -420,9 +420,79 @@ \section*{Examples} \newpage % ===========================(start ex 03) % \chapter{Exercise 03} -\extitle{Functional file} +\extitle{Elementary} \turnindir{ex03} \exnumber{03} +\exfiles{operations.py} +\exforbidden{None} +\makeheaderfilesforbidden + + +% ================================= % +% \section*{} +Write a program that takes two integers A and B as arguments and prints the result of the following operations: +\begin{42console} +Sum: A+B +Difference: A-B +Product: A*B +Quotient: A/B +Remainder: A%B +\end{42console} + +\begin{itemize} + \item If more or less than two argument are provided or if either of the argument is not an integer, print an error message. + \item If no argument are provided, do nothing or print an usage. + \item If an operation is impossible, print an error message instead of a numerical result. +\end{itemize} + +% ================================= % +\section*{Examples} +\begin{42console} +$> python3 operations.py 10 3 +Sum: 13 +Difference: 7 +Product: 30 +Quotient: 3.3333... +Remainder: 1 +$> +$> python3 operations.py 42 10 +Sum: 52 +Difference: 32 +Product: 420 +Quotient: 4.2 +Remainder: 2 +$> +$> python3 operations.py 1 0 +Sum: 1 +Difference: 1 +Product: 0 +Quotient: ERROR (division by zero) +Remainder: ERROR (modulo by zero) +$> +$> python3 operations.py +Usage: python operations.py +Example: + python operations.py 10 3 +$> +$> python3 operations.py 12 10 5 +AssertionError: too many arguments +$> +$> python3 operations.py "one" "two" +AssertionError: only integers +$> +\end{42console} + +\hint{ + No bonus point to be gained from handling decimal point or scientific notation. Keep it simple. +} + +% ===========================(fin ex 03) % +\newpage +% ===========================(start ex 04) % +\chapter{Exercise 04} +\extitle{Functional file} +\turnindir{ex04} +\exnumber{04} \exfiles{count.py} \exforbidden{None} \makeheaderfilesforbidden @@ -510,204 +580,13 @@ \subsection*{Examples} - 1 space(s) \end{42console} -% ===========================(fin ex 03) % -\newpage -% ===========================(start ex 04) % -\chapter{Exercise 04} -\extitle{Elementary} -\turnindir{ex04} -\exnumber{04} -\exfiles{operations.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -% \section*{} -Write a program that takes two integers A and B as arguments and prints the result of the following operations: -\begin{42console} -Sum: A+B -Difference: A-B -Product: A*B -Quotient: A/B -Remainder: A%B -\end{42console} - -\begin{itemize} - \item If more or less than two argument are provided or if either of the argument is not an integer, print an error message. - \item If no argument are provided, do nothing or print an usage. - \item If an operation is impossible, print an error message instead of a numerical result. -\end{itemize} - -% ================================= % -\section*{Examples} -\begin{42console} -$> python3 operations.py 10 3 -Sum: 13 -Difference: 7 -Product: 30 -Quotient: 3.3333... -Remainder: 1 -$> -$> python3 operations.py 42 10 -Sum: 52 -Difference: 32 -Product: 420 -Quotient: 4.2 -Remainder: 2 -$> -$> python3 operations.py 1 0 -Sum: 1 -Difference: 1 -Product: 0 -Quotient: ERROR (division by zero) -Remainder: ERROR (modulo by zero) -$> -$> python3 operations.py -Usage: python operations.py -Example: - python operations.py 10 3 -$> -$> python3 operations.py 12 10 5 -AssertionError: too many arguments -$> -$> python3 operations.py "one" "two" -AssertionError: only integers -$> -\end{42console} - -\hint{ - No bonus point to be gained from handling decimal point or scientific notation. Keep it simple. -} - % ===========================(fin ex 04) % \newpage % ===========================(start ex 05) % - \chapter{Exercise 05} -\extitle{The right format} +\extitle{A recipe} \turnindir{ex05} \exnumber{05} -\exfiles{kata00.py, kata01.py, kata02.py, kata03.py, kata04.py} -\exforbidden{None} -\makeheaderfilesforbidden - -Let's get familiar with the useful concept of \textbf{string formatting} through a kata series.\\ - -Each exercice will provide you with a \texttt{kata} variable. This variable can be modified to a certain extent: your program must react accordingly. - -% ================================= % -\section*{kata00} -The \texttt{kata} variable is always a tuple and can only be filled with integer. -\begin{42console} -# Put this at the top of your kata00.py file -kata = (19,42,21) -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata00.py -The 3 numbers are: 19, 42, 21 -$> -\end{42console} - -% ================================= % -\section*{kata01} - -The \texttt{kata} variable is always a dictionary and can only be filled with strings. - -\begin{42console} -# Put this at the top of your kata01.py file -kata = { - 'Python': 'Guido van Rossum', - 'Ruby': 'Yukihiro Matsumoto', - 'PHP': 'Rasmus Lerdorf', - } -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata01.py -Python was created by Guido van Rossum -Ruby was created by Yukihiro Matsumoto -PHP was created by Rasmus Lerdorf -$> -\end{42console} - -% ================================= % -\section*{kata02} - -The \texttt{kata} variable is always a tuple that contains 5 non-negative integers. The first integer contains up to 4 digits, the rest up to 2 digits. - -\begin{42console} -# Put this at the top of your kata02.py file -kata = (2019, 9, 25, 3, 30) -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata02.py | cat -e -09/25/2019 03:30$ -$> python3 kata02.py | wc -c -17 -$> -\end{42console} - -% ================================= % -\section*{kata03} - -The \texttt{kata} variable is always a string whose length is not higher than 42. - -\begin{42console} -# Put this at the top of your kata03.py file -kata = "The right format" -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata03.py | cat -e ---------------------------The right format% -$> python3 kata03.py | wc -c -42 -$> -\end{42console} - -% ================================= % -\section*{kata04} - -The \texttt{kata} variable is always a tuple that contains, in the following order: -\begin{itemize} - \item 2 non-negative integer containing up to 2 digits - \item 1 decimal - \item 1 integer - \item 1 decimal -\end{itemize} - -\begin{42console} -# Put this at the top of your kata04.py file -kata = (0, 4, 132.42222, 10000, 12345.67) -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata04.py -module_00, ex_04 : 132.42, 1.00e+04, 1.23e+04 -$> python3 kata04.py | cut -c 10,18 -,: -\end{42console} - -% ===========================(fin ex 05) % -\newpage -% ===========================(start ex 06) % -\chapter{Exercise 06} -\extitle{A recipe} -\turnindir{ex06} -\exnumber{06} \exfiles{recipe.py} \exforbidden{None} \makeheaderfilesforbidden @@ -811,13 +690,13 @@ \section*{Part 3: A command line executable !} \end{42console} -% ===========================(fin ex 06) % -\newpage -% ===========================(start ex 07) % -\chapter{Exercise 07} +% ===========================(fin ex 05) % +\newpage +% ===========================(start ex 06) % +\chapter{Exercise 06} \extitle{Shorter, faster, pythonest} -\turnindir{ex07} -\exnumber{07} +\turnindir{ex06} +\exnumber{06} \exfiles{filterwords.py} \exforbidden{filter} \makeheaderfilesforbidden @@ -851,49 +730,188 @@ \section*{Examples} ERROR \end{42console} +% ===========================(fin ex 06) % +\newpage +% ===========================(start ex 07) % + +\chapter{Exercise 07} +\extitle{The right format} +\turnindir{ex07} +\exnumber{07} +\exfiles{kata00.py, kata01.py, kata02.py, kata03.py, kata04.py} +\exforbidden{None} +\makeheaderfilesforbidden + +Let's get familiar with the useful concept of \textbf{string formatting} through a kata series.\\ + +Each exercice will provide you with a \texttt{kata} variable. This variable can be modified to a certain extent: your program must react accordingly. + +% ================================= % +\section*{kata00} +The \texttt{kata} variable is always a tuple and can only be filled with integer. +\begin{42console} +# Put this at the top of your kata00.py file +kata = (19,42,21) +\end{42console} + +Write a program that display this variable content according to the format shown below: + +\begin{42console} +$> python3 kata00.py +The 3 numbers are: 19, 42, 21 +$> +\end{42console} + +% ================================= % +\section*{kata01} + +The \texttt{kata} variable is always a dictionary and can only be filled with strings. + +\begin{42console} +# Put this at the top of your kata01.py file +kata = { + 'Python': 'Guido van Rossum', + 'Ruby': 'Yukihiro Matsumoto', + 'PHP': 'Rasmus Lerdorf', + } +\end{42console} + +Write a program that display this variable content according to the format shown below: + +\begin{42console} +$> python3 kata01.py +Python was created by Guido van Rossum +Ruby was created by Yukihiro Matsumoto +PHP was created by Rasmus Lerdorf +$> +\end{42console} + +% ================================= % +\section*{kata02} + +The \texttt{kata} variable is always a tuple that contains 5 non-negative integers. The first integer contains up to 4 digits, the rest up to 2 digits. + +\begin{42console} +# Put this at the top of your kata02.py file +kata = (2019, 9, 25, 3, 30) +\end{42console} + +Write a program that display this variable content according to the format shown below: + +\begin{42console} +$> python3 kata02.py | cat -e +09/25/2019 03:30$ +$> python3 kata02.py | wc -c +17 +$> +\end{42console} + +% ================================= % +\section*{kata03} + +The \texttt{kata} variable is always a string whose length is not higher than 42. + +\begin{42console} +# Put this at the top of your kata03.py file +kata = "The right format" +\end{42console} + +Write a program that display this variable content according to the format shown below: + +\begin{42console} +$> python3 kata03.py | cat -e +--------------------------The right format% +$> python3 kata03.py | wc -c +42 +$> +\end{42console} + +% ================================= % +\section*{kata04} + +The \texttt{kata} variable is always a tuple that contains, in the following order: +\begin{itemize} + \item 2 non-negative integer containing up to 2 digits + \item 1 decimal + \item 1 integer + \item 1 decimal +\end{itemize} + +\begin{42console} +# Put this at the top of your kata04.py file +kata = (0, 4, 132.42222, 10000, 12345.67) +\end{42console} + +Write a program that display this variable content according to the format shown below: + +\begin{42console} +$> python3 kata04.py +module_00, ex_04 : 132.42, 1.00e+04, 1.23e+04 +$> python3 kata04.py | cut -c 10,18 +,: +\end{42console} + % ===========================(fin ex 07) % \newpage +% ============================================== % % ===========================(start ex 08) % \chapter{Exercise 08} -\extitle{S.O.S} +\extitle{Loading bar!} \turnindir{ex08} \exnumber{08} -\exfiles{sos.py} -\exforbidden{None} +\exfiles{loading.py} +\exforbidden{\texttt{tqdm} or any library for automatic loading bar} \makeheaderfilesforbidden -Make a program that takes a string as argument and encode it into Morse code. -\begin{itemize} - \item The program supports space and alphanumeric characters - \item An alphanumeric character is represented by dots \texttt{.} and dashes \texttt{-}: - \item A space character is represented by a slash \texttt{/} - \item Complete morse characters are separated by a single space\\ -\end{itemize} +You are about to discover the \texttt{yield} operator! -If more than one argument are provided, merge them into a single string with each argument separated by a space character.\\ +So let's create a function called \texttt{ft\_progress(lst)}. + +The function will display the progress of a \texttt{for} loop. -If no argument is provided, do nothing or print an usage. % ================================= % \section*{Examples} +% --------------------------------- % +\begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON + listy = range(1000) + ret = 0 + for elem in ft_progress(listy): + ret += (elem + 3) % 5 + sleep(0.01) + print() + print(ret) +\end{42console} + \begin{42console} - $> python3 sos.py "SOS" - ... --- ... - $> python3 sos.py - $> python3 sos.py "HELLO / WORLD" - ERROR - $> python3 sos.py "96 BOULEVARD" "Bessiere" - ----. -.... / -... --- ..- .-.. . ...- .- .-. -.. / -... . ... ... .. . .-. . + $> python loading.py + ETA: 8.67s [ 23%][=====> ] 233/1000 | elapsed time 2.33s + ... + 2000 +\end{42console} + +\begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON + listy = range(3333) + ret = 0 + for elem in ft_progress(listy): + ret += elem + sleep(0.005) + print() + print(ret) +\end{42console} + +\begin{42console} + $> python loading.py + ETA: 14.67s [ 9%][=> ] 327/3333 | elapsed time 1.33s + ... + 5552778 \end{42console} +\info{We advise you to go take a look at the wonderful tqdm library, it will come in handy in many situations} -\hint{ - \url{https://morsecode.world/international/morse2.html} -} % ===========================(fin ex 08) % % ============================================== % - \newpage % ============================================== % @@ -978,65 +996,47 @@ \section*{Examples} \newpage -% ============================================== % % ===========================(start ex 10) % \chapter{Exercise 10} -\extitle{Loading bar!} +\extitle{S.O.S} \turnindir{ex10} \exnumber{10} -\exfiles{loading.py} -\exforbidden{\texttt{tqdm} or any library for automatic loading bar} +\exfiles{sos.py} +\exforbidden{None} \makeheaderfilesforbidden +Make a program that takes a string as argument and encode it into Morse code. -You are about to discover the \texttt{yield} operator! - -So let's create a function called \texttt{ft\_progress(lst)}. +\begin{itemize} + \item The program supports space and alphanumeric characters + \item An alphanumeric character is represented by dots \texttt{.} and dashes \texttt{-}: + \item A space character is represented by a slash \texttt{/} + \item Complete morse characters are separated by a single space\\ +\end{itemize} -The function will display the progress of a \texttt{for} loop. +If more than one argument are provided, merge them into a single string with each argument separated by a space character.\\ +If no argument is provided, do nothing or print an usage. % ================================= % \section*{Examples} -% --------------------------------- % -\begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON - listy = range(1000) - ret = 0 - for elem in ft_progress(listy): - ret += (elem + 3) % 5 - sleep(0.01) - print() - print(ret) -\end{42console} - -\begin{42console} - $> python loading.py - ETA: 8.67s [ 23%][=====> ] 233/1000 | elapsed time 2.33s - ... - 2000 -\end{42console} - -\begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON - listy = range(3333) - ret = 0 - for elem in ft_progress(listy): - ret += elem - sleep(0.005) - print() - print(ret) -\end{42console} - \begin{42console} - $> python loading.py - ETA: 14.67s [ 9%][=> ] 327/3333 | elapsed time 1.33s - ... - 5552778 + $> python3 sos.py "SOS" + ... --- ... + $> python3 sos.py + $> python3 sos.py "HELLO / WORLD" + ERROR + $> python3 sos.py "96 BOULEVARD" "Bessiere" + ----. -.... / -... --- ..- .-.. . ...- .- .-. -.. / -... . ... ... .. . .-. . \end{42console} -\info{We advise you to go take a look at the wonderful tqdm library, it will come in handy in many situations} +\hint{ + \url{https://morsecode.world/international/morse2.html} +} % ===========================(fin ex 10) % % ============================================== % + \newpage % ================================= % \section*{Contact} From 90f8ececb34e3ef14bdcdec20cdee35a3c05521f Mon Sep 17 00:00:00 2001 From: oroberts Date: Fri, 25 Nov 2022 14:35:01 +0100 Subject: [PATCH 2/6] Closed day01 --- module01/subject/en.subject.tex | 332 ++++++++++++++++---------------- 1 file changed, 166 insertions(+), 166 deletions(-) diff --git a/module01/subject/en.subject.tex b/module01/subject/en.subject.tex index 2d00cd52..9629504c 100644 --- a/module01/subject/en.subject.tex +++ b/module01/subject/en.subject.tex @@ -340,9 +340,173 @@ \section*{Examples} % ============================================== % % ===========================(start ex 02) % \chapter{Exercise 02} -\extitle{The Vector} +\extitle{Generator!} \turnindir{ex02} \exnumber{02} +\exfiles{generator.py} +\exauthorize{random.randint, random.choice} +\exforbidden{random.shuffle, random.sample} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of the exercise is to discover the concept of generator object in Python. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +Code a function called \texttt{generator} that takes a text as input (only printable characters), uses the string +parameter \texttt{sep} as a splitting parameter, and \texttt{yield}s the resulting substrings. + +The function can take an optional argument. +The options are: +\begin{itemize} + \item \texttt{shuffle}: shuffles the list of words, + \item \texttt{unique}: returns a list where each word appears only once, + \item \texttt{ordered}: alphabetically sorts the words. +\end{itemize} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + # function prototype + def generator(text, sep=" ", option=None): + '''Splits the text according to sep value and yield the substrings. + option precise if a action is performed to the substrings before it is yielded. + ''' +\end{minted} + +You can only call one option at a time. + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + >> text = "Le Lorem Ipsum est simplement du faux texte." + >> for word in generator(text, sep=" "): + ... print(word) + ... + Le + Lorem + Ipsum + est + simplement + du + faux + texte. + + >> for word in generator(text, sep=" ", option="shuffle"): + ... print(word) + ... + simplement + texte. + est + faux + Le + Lorem + Ipsum + du + + >> for word in generator(text, sep=" ", option="ordered"): + ... print(word) + ... + Ipsum + Le + Lorem + du + est + faux + simplement + texte. +\end{minted} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +>> text = "Lorem Ipsum Lorem Ipsum" +>> for word in generator(text, sep=" ", option="unique"): +... print(word) +... +Lorem +Ipsum +\end{minted} + +The function should return "ERROR" one time if the \texttt{text} argument is not a string, or if the \texttt{option} argument is not valid. + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +>> text = 1.0 +>> for word in generator(text, sep="."): +... print(word) +... +ERROR +\end{minted} + + +% ===========================(fin ex 02) % +% ============================================== % + +\newpage + +% ============================================== % +% ===========================(start ex 03) % +\chapter{Exercise 03} +\extitle{Working with lists} +\turnindir{ex03} +\exnumber{03} +\exfiles{eval.py} +\exauthorize{zip and enumerate} +\exforbidden{while} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of the exercise is to discover 2 useful methods for lists, tuples, +dictionnaries (iterable class objects more generally) named \texttt{zip} +and \texttt{enumerate}. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +Code a class \texttt{Evaluator}, that has two static functions named \texttt{zip\_evaluate} +and \texttt{enumerate\_evaluate}. + + +The goal of these 2 functions is to compute the sum of the lengths of every +\texttt{words} of a given list weighted by a list of coefficinents \texttt{coefs} (yes, the 2 functions should do the same thing). + +The lists \texttt{coefs} and \texttt{words} have to be the same length. If this is not the +case, the function should return -1. + +You have to obtain the desired result using \texttt{zip} in the \texttt{zip\_evaluate} function, +and with \texttt{enumerate} in the \texttt{enumerate\_evaluate} function. + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +>> from eval import Evaluator +>> +>> words = ["Le", "Lorem", "Ipsum", "est", "simple"] +>> coefs = [1.0, 2.0, 1.0, 4.0, 0.5] +>> Evaluator.zip_evaluate(coefs, words) +32.0 +>> words = ["Le", "Lorem", "Ipsum", "n'", "est", "pas", "simple"] +>> coefs = [0.0, -1.0, 1.0, -12.0, 0.0, 42.42] +>> Evaluator.enumerate_evaluate(coefs, words) +-1 +\end{minted} + + +% ===========================(fin ex 03) % +% ============================================== % + +\newpage +% ============================================== % +% ===========================(start ex 04) % +\chapter{Exercise 04} +\extitle{The Vector} +\turnindir{ex04} +\exnumber{04} \exfiles{vector.py, test.py} \exforbidden{Numpy library} \makeheaderfilesforbidden @@ -577,176 +741,12 @@ \section*{Mathematic notions} Do not forget to handle all types of error properly! -% ===========================(fin ex 02) % -% ============================================== % - -\newpage - -% ============================================== % -% ===========================(start ex 03) % -\chapter{Exercise 03} -\extitle{Generator!} -\turnindir{ex03} -\exnumber{03} -\exfiles{generator.py} -\exauthorize{random.randint, random.choice} -\exforbidden{random.shuffle, random.sample} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of the exercise is to discover the concept of generator object in Python. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -Code a function called \texttt{generator} that takes a text as input (only printable characters), uses the string -parameter \texttt{sep} as a splitting parameter, and \texttt{yield}s the resulting substrings. - -The function can take an optional argument. -The options are: -\begin{itemize} - \item \texttt{shuffle}: shuffles the list of words, - \item \texttt{unique}: returns a list where each word appears only once, - \item \texttt{ordered}: alphabetically sorts the words. -\end{itemize} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - # function prototype - def generator(text, sep=" ", option=None): - '''Splits the text according to sep value and yield the substrings. - option precise if a action is performed to the substrings before it is yielded. - ''' -\end{minted} - -You can only call one option at a time. - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - >> text = "Le Lorem Ipsum est simplement du faux texte." - >> for word in generator(text, sep=" "): - ... print(word) - ... - Le - Lorem - Ipsum - est - simplement - du - faux - texte. - - >> for word in generator(text, sep=" ", option="shuffle"): - ... print(word) - ... - simplement - texte. - est - faux - Le - Lorem - Ipsum - du - - >> for word in generator(text, sep=" ", option="ordered"): - ... print(word) - ... - Ipsum - Le - Lorem - du - est - faux - simplement - texte. -\end{minted} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} ->> text = "Lorem Ipsum Lorem Ipsum" ->> for word in generator(text, sep=" ", option="unique"): -... print(word) -... -Lorem -Ipsum -\end{minted} - -The function should return "ERROR" one time if the \texttt{text} argument is not a string, or if the \texttt{option} argument is not valid. - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} ->> text = 1.0 ->> for word in generator(text, sep="."): -... print(word) -... -ERROR -\end{minted} - - -% ===========================(fin ex 03) % -% ============================================== % - -\newpage - -% ============================================== % -% ===========================(start ex 04) % -\chapter{Exercise 04} -\extitle{Working with lists} -\turnindir{ex04} -\exnumber{04} -\exfiles{eval.py} -\exauthorize{zip and enumerate} -\exforbidden{while} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of the exercise is to discover 2 useful methods for lists, tuples, -dictionnaries (iterable class objects more generally) named \texttt{zip} -and \texttt{enumerate}. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -Code a class \texttt{Evaluator}, that has two static functions named \texttt{zip\_evaluate} -and \texttt{enumerate\_evaluate}. - - -The goal of these 2 functions is to compute the sum of the lengths of every -\texttt{words} of a given list weighted by a list of coefficinents \texttt{coefs} (yes, the 2 functions should do the same thing). - -The lists \texttt{coefs} and \texttt{words} have to be the same length. If this is not the -case, the function should return -1. - -You have to obtain the desired result using \texttt{zip} in the \texttt{zip\_evaluate} function, -and with \texttt{enumerate} in the \texttt{enumerate\_evaluate} function. - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} ->> from eval import Evaluator ->> ->> words = ["Le", "Lorem", "Ipsum", "est", "simple"] ->> coefs = [1.0, 2.0, 1.0, 4.0, 0.5] ->> Evaluator.zip_evaluate(coefs, words) -32.0 ->> words = ["Le", "Lorem", "Ipsum", "n'", "est", "pas", "simple"] ->> coefs = [0.0, -1.0, 1.0, -12.0, 0.0, 42.42] ->> Evaluator.enumerate_evaluate(coefs, words) --1 -\end{minted} - - % ===========================(fin ex 04) % % ============================================== % \newpage + % ============================================== % % ===========================(start ex 05) % \chapter{Exercise 05} From 1822586d69b31108d4484b3ef0e6f848f8983d05 Mon Sep 17 00:00:00 2001 From: oroberts Date: Fri, 25 Nov 2022 14:37:12 +0100 Subject: [PATCH 3/6] closed day02 --- module02/subject/en.subject.tex | 186 ++++++++++++++++---------------- 1 file changed, 94 insertions(+), 92 deletions(-) diff --git a/module02/subject/en.subject.tex b/module02/subject/en.subject.tex index 4c9ca377..52d29198 100644 --- a/module02/subject/en.subject.tex +++ b/module02/subject/en.subject.tex @@ -349,9 +349,91 @@ \section*{Examples} % ============================================== % % ===========================(start ex 02) % \chapter{Exercise 02} -\extitle{The logger} +\extitle{TinyStatistician} \turnindir{ex02} \exnumber{02} +\exfiles{TinyStatistician.py} +\exforbidden{Any function that calculates mean, median, quartiles, variance or standar deviation for you.} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +Initiation to very basic statistic notions. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +Create a class named \texttt{TinyStatistician} that implements the following methods: +\begin{itemize} + \item \texttt{mean(x)}: computes the mean of a given non-empty list or array \texttt{x}, using a for-loop. + The method returns the mean as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its mean is: + $$ + \mu = \frac{\sum_{i = 1}^{m}{x_i}}{m} + $$ + \item \texttt{median(x)}: computes the median of a given non-empty list or array \texttt{x}. + The method returns the median as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + \item \texttt{quartiles(x)}: computes the $1^{\text{st}}$ and $3^{\text{rd}}$ quartiles of a given non-empty array \texttt{x}. + The method returns the quartile as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + \item \texttt{var(x)}: computes the variance of a given non-empty list or array \texttt{x}, using a for-loop. + The method returns the variance as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its variance is: + $$ + \sigma^2 = \frac{\sum_{i = 1}^{m}{(x_i - \mu)^2}}{m} = \frac{\sum_{i = 1}^{m}{[x_i - (\frac{1}{m}\sum_{j = 1}^{m}{x_j}})]^2}{m} + $$ + \item \texttt{std(x)} : computes the standard deviation of a given non-empty list or array \texttt{x}, using a for-loop. + The method returns the standard deviation as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its standard deviation is: + $$ + \sigma = \sqrt{\frac{\sum_{i = 1}^{m}{(x_i - \mu)^2}}{m}} = \sqrt{\frac{\sum_{i = 1}^{m}{[x_i - (\frac{1}{m}\sum_{j = 1}^{m}{x_j}})]^2}{m}} + $$ +\end{itemize} + +All methods take a \texttt{list} or a \texttt{numpy.ndarray} as parameter.\\ +We are assuming that all inputs have a correct format, i.e. a list or array of numeric type or empty list or array. +You don't have to protect your functions against input errors. + + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from TinyStatistician import TinyStatistician +tstat = TinyStatistician() +a = [1, 42, 300, 10, 59] + +tstat.mean(a) +# Expected result: 82.4 + +tstat.median(a) +# Expected result: 42.0 + +tstat.quartile(a) +# Expected result: [10.0, 59.0] + +tstat.var(a) +# Expected result: 12279.439999999999 + +tstat.std(a) +# Expected result: 110.81263465868862 +\end{minted} + + + +% ===========================(fin ex 02) % +% ============================================== % + +\newpage + + +% ============================================== % +% ===========================(start ex 03) % +\chapter{Exercise 03} +\extitle{The logger} +\turnindir{ex03} +\exnumber{03} \exfiles{logger.py} \exforbidden{None} \makeheaderfilesforbidden @@ -466,17 +548,17 @@ \section*{Examples} Pay attention, the length between ":" and "[" is 20]. Draw the corresponding conclusions on this part of a log entry. -% ===========================(fin ex 02) % +% ===========================(fin ex 03) % % ============================================== % \newpage % ============================================== % -% ===========================(start ex 03) % -\chapter{Exercise 03} +% ===========================(start ex 04) % +\chapter{Exercise 04} \extitle{Json issues} -\turnindir{ex03} -\exnumber{03} +\turnindir{ex04} +\exnumber{04} \exfiles{csvreader.py} \exforbidden{None} \makeheaderfilesforbidden @@ -572,17 +654,17 @@ \section*{Instructions} \end{minted} -% ===========================(fin ex 03) % +% ===========================(fin ex 04) % % ============================================== % \newpage % ============================================== % -% ===========================(start ex 04) % -\chapter{Exercise 04} +% ===========================(start ex 05) % +\chapter{Exercise 05} \extitle{MiniPack} -\turnindir{ex04} -\exnumber{04} +\turnindir{ex05} +\exnumber{05} \exfiles{build.sh, *.py, *.md, *.cfg, *.txt} \exforbidden{None} \makeheaderfilesforbidden @@ -677,91 +759,11 @@ \section*{Instructions} \texttt{pip show -v my\_minipack}. Of course do not reproduce the exact same metadata, change the author information, modify the summary Topic and Audience items if you want to. } -% ===========================(fin ex 04) % -% ============================================== % -\newpage - -% ============================================== % -% ===========================(start ex 05) % -\chapter{Exercise 05} -\extitle{TinyStatistician} -\turnindir{ex05} -\exnumber{05} -\exfiles{TinyStatistician.py} -\exforbidden{Any function that calculates mean, median, quartiles, variance or standar deviation for you.} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -Initiation to very basic statistic notions. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -Create a class named \texttt{TinyStatistician} that implements the following methods: -\begin{itemize} - \item \texttt{mean(x)}: computes the mean of a given non-empty list or array \texttt{x}, using a for-loop. - The method returns the mean as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its mean is: - $$ - \mu = \frac{\sum_{i = 1}^{m}{x_i}}{m} - $$ - \item \texttt{median(x)}: computes the median of a given non-empty list or array \texttt{x}. - The method returns the median as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - \item \texttt{quartiles(x)}: computes the $1^{\text{st}}$ and $3^{\text{rd}}$ quartiles of a given non-empty array \texttt{x}. - The method returns the quartile as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - \item \texttt{var(x)}: computes the variance of a given non-empty list or array \texttt{x}, using a for-loop. - The method returns the variance as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its variance is: - $$ - \sigma^2 = \frac{\sum_{i = 1}^{m}{(x_i - \mu)^2}}{m} = \frac{\sum_{i = 1}^{m}{[x_i - (\frac{1}{m}\sum_{j = 1}^{m}{x_j}})]^2}{m} - $$ - \item \texttt{std(x)} : computes the standard deviation of a given non-empty list or array \texttt{x}, using a for-loop. - The method returns the standard deviation as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its standard deviation is: - $$ - \sigma = \sqrt{\frac{\sum_{i = 1}^{m}{(x_i - \mu)^2}}{m}} = \sqrt{\frac{\sum_{i = 1}^{m}{[x_i - (\frac{1}{m}\sum_{j = 1}^{m}{x_j}})]^2}{m}} - $$ -\end{itemize} - -All methods take a \texttt{list} or a \texttt{numpy.ndarray} as parameter.\\ -We are assuming that all inputs have a correct format, i.e. a list or array of numeric type or empty list or array. -You don't have to protect your functions against input errors. - - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from TinyStatistician import TinyStatistician -tstat = TinyStatistician() -a = [1, 42, 300, 10, 59] - -tstat.mean(a) -# Expected result: 82.4 - -tstat.median(a) -# Expected result: 42.0 - -tstat.quartile(a) -# Expected result: [10.0, 59.0] - -tstat.var(a) -# Expected result: 12279.439999999999 - -tstat.std(a) -# Expected result: 110.81263465868862 -\end{minted} - - - % ===========================(fin ex 05) % % ============================================== % - \newpage + % ================================= % \section*{Contact} % --------------------------------- % From fec044c3c7e1f77588078296924a4bf95b1058d8 Mon Sep 17 00:00:00 2001 From: oroberts Date: Fri, 25 Nov 2022 14:41:55 +0100 Subject: [PATCH 4/6] closed day04 (03 was ok) --- module04/subject/en.subject.tex | 161 ++++++++++++++++---------------- 1 file changed, 81 insertions(+), 80 deletions(-) diff --git a/module04/subject/en.subject.tex b/module04/subject/en.subject.tex index ac4f1240..7af4444f 100644 --- a/module04/subject/en.subject.tex +++ b/module04/subject/en.subject.tex @@ -402,9 +402,83 @@ \section*{Examples} % ============================================== % % ===========================(start ex 04) % \chapter{Exercise 04} -\extitle{SpatioTemporalData} +\extitle{MyPlotLib} \turnindir{ex04} \exnumber{04} +\exfiles{MyPlotLib.py} +\exforbidden{None} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal the exercise is to introduce plotting methods among the different +libraries Pandas, Matplotlib, Seaborn or Scipy. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +This exercise uses the following dataset: \texttt{athlete\_events.csv} + +Write a class called \texttt{MyPlotLib}. This class implements different plotting +methods, each of which take two arguments: +\begin{itemize} + \item a pandas.DataFrame which contains the dataset, + \item a list of feature names. +\end{itemize} + +\hint{ + What is a feature? https://towardsdatascience.com/feature-engineering-for-machine-learning-3a5e293a5114 +} + +\begin{itemize} + \item \texttt{histogram(data, features)}: plots one histogram for each numerical feature in the list, + \item \texttt{density(data, features)}: plots the density curve of each numerical feature in the list, + \item \texttt{pair\_plot(data, features)}: plots a matrix of subplots (also called scatter plot matrix). + On each subplot shows a scatter plot of one numerical variable against another one. + The main diagonal of this matrix shows simple histograms. + \item \texttt{box\_plot(data, features)}: displays a box plot for each numerical variable in the dataset. +\end{itemize} + +% ================================= % +\section*{Examples} +% --------------------------------- % + +\begin{figure}[h!] + \begin{minipage}[l]{0.49\linewidth} + \includegraphics[scale=0.39]{assets/ex06_histogram.png} + \caption{histogram} + \end{minipage} + \hfill + \begin{minipage}[c]{0.49\linewidth} + \includegraphics[scale=0.39]{assets/ex06_density.png} + \caption{density} + \end{minipage} + + \begin{minipage}[l]{0.49\linewidth} + \includegraphics[scale=0.39]{assets/ex06_pair_plot.png} + \caption{pair plot} + \end{minipage} + \hfill + \begin{minipage}[c]{0.49\linewidth} + \includegraphics[scale=0.39]{assets/ex06_box_plot.png} + \caption{box plot} + \end{minipage} +\end{figure} + + +% ===========================(fin ex 04) % +% ============================================== % + +\newpage + +% ============================================== % +% ===========================(start ex 05) % +\chapter{Exercise 05} +\extitle{SpatioTemporalData} +\turnindir{ex05} +\exnumber{05} \exfiles{FileLoader.py, SpatioTemporalData.py} \exforbidden{None} \makeheaderfilesforbidden @@ -467,17 +541,17 @@ \section*{Examples} \end{minted} -% ===========================(fin ex 04) % +% ===========================(fin ex 05) % % ============================================== % \newpage % ============================================== % -% ===========================(start ex 05) % -\chapter{Exercise 05} +% ===========================(start ex 06) % +\chapter{Exercise 06} \extitle{HowManyMedalsByCountry} -\turnindir{ex05} -\exnumber{05} +\turnindir{ex06} +\exnumber{06} \exfiles{FileLoader.py, HowManyMedalsByCountry.py} \exforbidden{None} \makeheaderfilesforbidden @@ -542,85 +616,12 @@ \section*{Examples} The \texttt{athlete\_events.csv} dataset might not always take these posterior changes into account. -% ===========================(fin ex 05) % -% ============================================== % - -\newpage - -% ============================================== % -% ===========================(start ex 06) % -\chapter{Exercise 06} -\extitle{MyPlotLib} -\turnindir{ex06} -\exnumber{06} -\exfiles{MyPlotLib.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal the exercise is to introduce plotting methods among the different -libraries Pandas, Matplotlib, Seaborn or Scipy. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -This exercise uses the following dataset: \texttt{athlete\_events.csv} - -Write a class called \texttt{MyPlotLib}. This class implements different plotting -methods, each of which take two arguments: -\begin{itemize} - \item a pandas.DataFrame which contains the dataset, - \item a list of feature names. -\end{itemize} - -\hint{ - What is a feature? https://towardsdatascience.com/feature-engineering-for-machine-learning-3a5e293a5114 -} - -\begin{itemize} - \item \texttt{histogram(data, features)}: plots one histogram for each numerical feature in the list, - \item \texttt{density(data, features)}: plots the density curve of each numerical feature in the list, - \item \texttt{pair\_plot(data, features)}: plots a matrix of subplots (also called scatter plot matrix). - On each subplot shows a scatter plot of one numerical variable against another one. - The main diagonal of this matrix shows simple histograms. - \item \texttt{box\_plot(data, features)}: displays a box plot for each numerical variable in the dataset. -\end{itemize} - -% ================================= % -\section*{Examples} -% --------------------------------- % - -\begin{figure}[h!] - \begin{minipage}[l]{0.49\linewidth} - \includegraphics[scale=0.39]{assets/ex06_histogram.png} - \caption{histogram} - \end{minipage} - \hfill - \begin{minipage}[c]{0.49\linewidth} - \includegraphics[scale=0.39]{assets/ex06_density.png} - \caption{density} - \end{minipage} - - \begin{minipage}[l]{0.49\linewidth} - \includegraphics[scale=0.39]{assets/ex06_pair_plot.png} - \caption{pair plot} - \end{minipage} - \hfill - \begin{minipage}[c]{0.49\linewidth} - \includegraphics[scale=0.39]{assets/ex06_box_plot.png} - \caption{box plot} - \end{minipage} -\end{figure} - - % ===========================(fin ex 06) % % ============================================== % \newpage + % ============================================== % % ===========================(start ex 07) % \chapter{Exercise 07} From e472a9f5e49cbf9045ff09473ab3b1128189aa02 Mon Sep 17 00:00:00 2001 From: madvid Date: Tue, 29 Nov 2022 23:54:04 +0100 Subject: [PATCH 5/6] update version --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 6c8dc7eb..857572fc 100644 --- a/version +++ b/version @@ -1 +1 @@ -v3.1.0 +v4.0.0 From 72ab9ab8729f47f6b98ecc36565b21e8f41f0313 Mon Sep 17 00:00:00 2001 From: oroberts Date: Wed, 30 Nov 2022 13:36:33 +0100 Subject: [PATCH 6/6] Error on py04 ex 06 the list of country sports was going out of screen. Added somm line returns --- module04/subject/en.subject.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module04/subject/en.subject.tex b/module04/subject/en.subject.tex index 7af4444f..7dc711bb 100644 --- a/module04/subject/en.subject.tex +++ b/module04/subject/en.subject.tex @@ -581,8 +581,8 @@ \section*{Instructions} year's dictionary, the key are 'G', 'S', 'B' corresponding to the type of medals won. -Duplicated medals per team games should be handled and not counted twice. -Hint: You may find this list to be of some use. +Duplicated medals per team games should be handled and not counted twice.\\ +Hint: You may find this list to be of some use.\\ \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} team_sports = ['Basketball', 'Football', 'Tug-Of-War', 'Badminton', 'Sailing', 'Handball', 'Water Polo', 'Hockey', 'Rowing', 'Bobsleigh', 'Softball',