Skip to content

Commit ff58883

Browse files
committed
MV - refacto m00 + m01
1 parent 417b1e3 commit ff58883

29 files changed

+761
-846
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ __pycache__/
99
# C extensions
1010
*.so
1111

12+
# Latex compilation files
13+
*.fdb_latexmk
14+
*.fls
15+
*.pdf.version
16+
1217
# Distribution / packaging
1318
.Python
1419
develop-eggs/

module00/subject/en.subject.fdb_latexmk

Lines changed: 0 additions & 15 deletions
This file was deleted.

module00/subject/en.subject.fls

Lines changed: 0 additions & 7 deletions
This file was deleted.

module00/subject/en.subject.pdf

0 Bytes
Binary file not shown.

module00/subject/en.subject.pdf.version

Lines changed: 0 additions & 1 deletion
This file was deleted.

module00/subject/en.subject.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
\author{}
104104
\summary{The goal of this module is to get you started with Python}
105105
\maketitle
106-
\input{en.py_proj.tex}
106+
\input{en.instruction.tex}
107107
\newpage
108108
\tableofcontents
109109
\startexercices
@@ -160,7 +160,7 @@
160160
% ===========================(fin ex 10) %
161161
\newpage
162162
% ================================= %
163-
\input{acknowledgements.tex}
163+
\input{en.acknowledgements.tex}
164164
% ================================= %
165165

166166
\end{document}

module01/exercises/m01ex00.tex

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
\chapter{Exercise 00}
2+
\extitle{The Book}
3+
\turnindir{ex00}
4+
\exnumber{00}
5+
\exfiles{book.py, recipe.py, test.py}
6+
\exforbidden{None}
7+
\makeheaderfilesforbidden
8+
9+
% ================================== %
10+
\section*{Objective}
11+
% ---------------------------------- %
12+
The goal of this exercise is to get you familiar with the notions of
13+
classes and the manipulation of the objects related to these classes.
14+
15+
% ================================== %
16+
\section*{Instructions}
17+
% ---------------------------------- %
18+
You will have to make a class \texttt{Book} and a class \texttt{Recipe}.
19+
The classes \texttt{Book} and \texttt{Recipe} will be written in
20+
\texttt{book.py} and \texttt{recipe.py} respectively.\\
21+
\newline
22+
Let's describe the \texttt{Recipe} class. It has some attributes:
23+
\begin{itemize}
24+
\item \texttt{name} (str): name of the recipe,
25+
\item \texttt{cooking\_lvl} (int): range from $1$ to $5$,
26+
\item \texttt{cooking\_time} (int): in minutes (no negative numbers),
27+
\item \texttt{ingredients} (list): list of all ingredients each represented by a string,
28+
\item \texttt{description} (str): description of the recipe,
29+
\item \texttt{recipe\_type} (str): can be "starter", "lunch" or "dessert".
30+
\end{itemize}
31+
You have to \textbf{initialize} the object \texttt{Recipe} and check all of its values. Only the description can be empty.
32+
In case of input errors, you should print what they are and exit properly.\\
33+
\newline
34+
You will have to implement the built-in method \texttt{\_\_str\_\_}.
35+
It's the method called when the following code is executed:\\
36+
\newline
37+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
38+
tourte = Recipe(...)
39+
to_print = str(tourte)
40+
print(to_print)
41+
\end{minted}
42+
\newline
43+
\newline
44+
It is implemented this way:\\
45+
\newline
46+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
47+
def __str__(self):
48+
"""Returns the string to print with the recipe's info"""
49+
txt = ""
50+
"""Your code here"""
51+
return txt
52+
\end{minted}
53+
\newline
54+
The \texttt{Book} class also has some attributes:
55+
\begin{itemize}
56+
\item \texttt{name} (str): name of the book,
57+
\item \texttt{last\_update} \href{https://docs.python.org/3/library/datetime.html}{(datetime)}: the date of the last update,
58+
\item \texttt{creation\_date} \href{https://docs.python.org/3/library/datetime.html}{(datetime)}: the creation date of the book,
59+
\item \texttt{recipes\_list} (dict): a dictionnary with 3 keys: "starter", "lunch", "dessert".
60+
\end{itemize}
61+
You will have to implement some methods in the \texttt{Book} class:\\
62+
\newline
63+
\begin{minted}[bgcolor=darcula-back ,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
64+
def get_recipe_by_name(self, name):
65+
"""Prints a recipe with the name \texttt{name} and returns the instance"""
66+
#... Your code here ...
67+
68+
def get_recipes_by_types(self, recipe_type):
69+
"""Gets all recipes names for a given recipe_type """
70+
#... Your code here ...
71+
72+
def add_recipe(self, recipe):
73+
"""Adds a recipe to the book and updates last_update"""
74+
#... Your code here ...
75+
\end{minted}
76+
\newline
77+
You have to handle the error if the argument passed in \texttt{add\_recipe} is not a \texttt{Recipe}.\\
78+
\newline
79+
Finally, you will provide a \texttt{test.py} file to test your classes and prove that they are working properly.
80+
You can import all the classes into your \texttt{test.py} file by adding these lines at the top of the \texttt{test.py} file:\\
81+
\newline
82+
\begin{minted}[bgcolor=darcula-back ,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
83+
from book import Book
84+
from recipe import Recipe
85+
86+
# ... Your tests ...
87+
\end{minted}

module01/exercises/m01ex01.tex

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
\chapter{Exercise 01}
2+
\extitle{Family tree}
3+
\turnindir{ex01}
4+
\exnumber{01}
5+
\exfiles{game.py}
6+
\exforbidden{None}
7+
\makeheaderfilesforbidden
8+
9+
% ================================= %
10+
\section*{Objective}
11+
% --------------------------------- %
12+
The goal of the exercise is to tackle the notion of class inheritance.
13+
14+
% ================================= %
15+
\section*{Instructions}
16+
% --------------------------------- %
17+
Create a \texttt{GotCharacter} class and initialize it with the following attributes:
18+
\begin{itemize}
19+
\item \texttt{first\_name},
20+
\item \texttt{is\_alive} (by default is \texttt{True}).
21+
\end{itemize}
22+
Pick up a Game of Thrones House (e.g., Stark, Lannister...), create a child class that inherits from \texttt{GotCharacter} and
23+
define the following attributes:
24+
\begin{itemize}
25+
\item \texttt{family\_name} (by default should be the same as the Class)
26+
\item \texttt{house\_words} (e.g., the House words for the Stark House is: "Winter is Coming")\\
27+
\end{itemize}
28+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
29+
class Stark(GotCharacter):
30+
def __init__(self, first_name=None, is_alive=True):
31+
super().__init__(first_name=first_name, is_alive=is_alive)
32+
self.family_name = "Stark"
33+
self.house_words = "Winter is Coming"
34+
\end{minted}
35+
36+
\newpage
37+
Add two methods to your child class:
38+
\begin{itemize}
39+
\item \texttt{print\_house\_words}: prints the House words,
40+
\item \texttt{die}: changes the value of \texttt{is\_alive} to \texttt{False}.
41+
\end{itemize}
42+
43+
\section*{Examples}
44+
Running commands in the Python console, an example of what you should get:\\
45+
\newline
46+
47+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
48+
$> python
49+
>>> from game import Stark
50+
51+
>>> arya = Stark("Arya")
52+
>>> print(arya.__dict__)
53+
{'first_name': 'Arya', 'is_alive': True, 'family_name': 'Stark', 'house_words': 'Winter is Coming'}
54+
55+
>>> arya.print_house_words()
56+
Winter is Coming
57+
58+
>>> print(arya.is_alive)
59+
True
60+
61+
>>> arya.die()
62+
>>> print(arya.is_alive)
63+
False
64+
\end{minted}
65+
\newline
66+
You can add any attribute or method you need to your class and format the docstring the way you want.
67+
Feel free to create other children of \texttt{GotCharacter} class.
68+
\newline
69+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
70+
$> python
71+
>>> from game import Stark
72+
73+
>>> arya = Stark("Arya")
74+
>>> print(arya.__doc__)
75+
A class representing the Stark family. Or when bad things happen to good people.
76+
\end{minted}

0 commit comments

Comments
 (0)