Skip to content

Commit a6d6eaf

Browse files
committed
3.3.0
1 parent 48df106 commit a6d6eaf

27 files changed

+462
-562
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
FIX wrong example for D01 ex03 "vector"
1+
- One file per exercise
2+
- Indentation fixes
3+
- Makefile update to clean latex compilation files
24

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ all: clean dirs
1313
%.pdf:
1414
@echo "We are taking care of: $@"
1515
@$(MAKE) -C $(shell dirname $@)
16+
@$(MAKE) clean -C $(shell dirname $@)
1617
cp $@ build/$(shell dirname `dirname $@`).pdf
1718

1819
dirs: $(TARGETS_DIRS)

build/module00.pdf

21.6 KB
Binary file not shown.

build/module01.pdf

156 KB
Binary file not shown.

build/module02.pdf

156 KB
Binary file not shown.

build/module03.pdf

156 KB
Binary file not shown.

build/module04.pdf

155 KB
Binary file not shown.

module00/subject/en.subject.pdf

0 Bytes
Binary file not shown.

module01/subject/en.subject.pdf

0 Bytes
Binary file not shown.

module02/subject/en.subject.pdf

0 Bytes
Binary file not shown.

module03/subject/en.subject.pdf

0 Bytes
Binary file not shown.

module04/exercises/m04ex00.tex

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
\chapter{Exercise 00}
2+
\extitle{FileLoader}
3+
\turnindir{ex00}
4+
\exnumber{00}
5+
\exfiles{FileLoader.py}
6+
\exforbidden{None}
7+
\makeheaderfilesforbidden
8+
9+
% ================================== %
10+
\section*{Objective}
11+
% ---------------------------------- %
12+
The goal of this exercise is to create a Fileloader class containing a
13+
load and a display method.
14+
15+
% ================================== %
16+
\section*{Instructions}
17+
% ---------------------------------- %
18+
Write a class named \texttt{FileLoader} which implements the following methods:
19+
\begin{itemize}
20+
\item \texttt{load(self, path)}: takes as an argument the file path of the dataset to load,
21+
displays a message specifying the dimensions of the dataset (e.g. 340 x 500)
22+
and returns the dataset loaded as a pandas.DataFrame.
23+
\item \texttt{display(self, df, n)}: takes a pandas.DataFrame and an integer as arguments,
24+
displays the first n rows of the dataset if n is positive, or the last n rows if n is negative.
25+
\end{itemize}
26+
27+
28+
\noindent \texttt{FileLoader} object should not raise any exceptions (wrong path, file does not exist, parameters different than a string ...).
29+
% ================================== %
30+
\section*{Examples}
31+
% ---------------------------------- %
32+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
33+
from FileLoader import FileLoader
34+
loader = FileLoader()
35+
data = loader.load("../data/adult_data.csv")
36+
# Output
37+
Loading dataset of dimensions 32561 x 15
38+
39+
40+
loader.display(data, 12)
41+
# Output
42+
age workclass fnlwgt ... hours-per-week native-country salary
43+
0 39 State-gov 77516 ... 40 United-States <=50K
44+
1 50 Self-emp-not-inc 83311 ... 13 United-States <=50K
45+
2 38 Private 215646 ... 40 United-States <=50K
46+
3 53 Private 234721 ... 40 United-States <=50K
47+
4 28 Private 338409 ... 40 Cuba <=50K
48+
5 37 Private 284582 ... 40 United-States <=50K
49+
6 49 Private 160187 ... 16 Jamaica <=50K
50+
7 52 Self-emp-not-inc 209642 ... 45 United-States >50K
51+
8 31 Private 45781 ... 50 United-States >50K
52+
9 42 Private 159449 ... 40 United-States >50K
53+
10 37 Private 280464 ... 80 United-States >50K
54+
11 30 State-gov 141297 ... 40 India >50K
55+
56+
[12 rows x 15 columns]
57+
\end{minted}
58+
59+
\hint{NB: Your terminal may display more columns if the window is wider.}

module04/exercises/m04ex01.tex

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
\chapter{Exercise 01}
2+
\extitle{YoungestFellah}
3+
\turnindir{ex01}
4+
\exnumber{01}
5+
\exfiles{FileLoader.py, YoungestFellah.py}
6+
\exforbidden{None}
7+
\makeheaderfilesforbidden
8+
9+
10+
% ================================= %
11+
\section*{Objective}
12+
% --------------------------------- %
13+
The goal of this exercise is to create a function that will return a
14+
dictionary containing the age of the youngest woman and the youngest
15+
man who took part in the Olympics for a given year.
16+
17+
% ================================= %
18+
\section*{Instructions}
19+
% --------------------------------- %
20+
This exercise uses the following dataset: \texttt{athlete\_events.csv}.\\
21+
\\
22+
Write a function \texttt{youngest\_fellah} that takes two arguments:
23+
\begin{itemize}
24+
\item a pandas.DataFrame which contains the dataset
25+
\item an Olympic year.
26+
\end{itemize}
27+
The function returns a dictionary containing the age of the youngest
28+
woman and man who took part in the Olympics on that year.
29+
The names of the dictionary's keys are up to you, but they must be explicit and self-explanatory.
30+
31+
% ================================= %
32+
\section*{Examples}
33+
% --------------------------------- %
34+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
35+
from FileLoader import FileLoader
36+
loader = FileLoader()
37+
data = loader.load('../data/athlete_events.csv')
38+
# Output
39+
Loading dataset of dimensions 271116 x 15
40+
41+
from YoungestFellah import youngest_fellah
42+
youngest_fellah(data, 2004)
43+
# Output
44+
{'f': 13.0, 'm': 14.0}
45+
\end{minted}

module04/exercises/m04ex02.tex

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
\chapter{Exercise 02}
2+
\extitle{ProportionBySport}
3+
\turnindir{ex02}
4+
\exnumber{02}
5+
\exfiles{FileLoader.py, ProportionBySport.py}
6+
\exforbidden{None}
7+
\makeheaderfilesforbidden
8+
9+
% ================================= %
10+
\section*{Objective}
11+
% --------------------------------- %
12+
The goal of this exercise is to create a function displaying
13+
the proportion of participants who played a given sport, among
14+
the participants of a given gender.
15+
16+
% ================================= %
17+
\section*{Instructions}
18+
% --------------------------------- %
19+
This exercise uses the dataset \texttt{athlete\_events.csv}.
20+
21+
Write a function \texttt{proportion\_by\_sport} that takes four arguments:
22+
\begin{itemize}
23+
\item a pandas.DataFrame of the dataset,
24+
\item an olympic year,
25+
\item a sport,
26+
\item a gender.
27+
\end{itemize}
28+
The function returns a float corresponding to the proportion (percentage) of participants
29+
who played the given sport among the participants of the given gender.\\
30+
\\
31+
The function answers questions like the following :
32+
"What was the percentage of female basketball players among all female
33+
participants in the 2016 Olympics?"
34+
35+
\hint{
36+
Here and later on, if needed, drop duplicate sports people to count only unique ones. Beware to call the dropping function
37+
at the right moment and with the right parameters, in order not to omit any individual.
38+
}
39+
40+
% ================================= %
41+
\section*{Examples}
42+
% --------------------------------- %
43+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
44+
from FileLoader import FileLoader
45+
loader = FileLoader()
46+
data = loader.load('../data/athlete_events.csv')
47+
# Output
48+
Loading dataset of dimensions 271116 x 15
49+
50+
51+
from ProportionBySport import proportion_by_sport
52+
proportion_by_sport(data, 2004, 'Tennis', 'F')
53+
# Output
54+
0.019302325581395347
55+
\end{minted}
56+
\newline
57+
We assume that we are always using valid arguments as input,
58+
and thus do not need to handle input errors.

module04/exercises/m04ex03.tex

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
\chapter{Exercise 03}
2+
\extitle{HowManyMedals}
3+
\turnindir{ex03}
4+
\exnumber{03}
5+
\exfiles{FileLoader.py, HowManyMedals.py}
6+
\exforbidden{None}
7+
\makeheaderfilesforbidden
8+
9+
10+
% ================================= %
11+
\section*{Objective}
12+
% --------------------------------- %
13+
The goal of this exercise is to implement a function that will return
14+
a dictionary of dictionaries giving the number and types of medals
15+
for each year during which the participant won medals.
16+
17+
% ================================= %
18+
\section*{Instructions}
19+
% --------------------------------- %
20+
This exercise uses the following dataset: \texttt{athlete\_events.csv}.
21+
22+
23+
Write a function \texttt{how\_many\_medals} that takes two arguments:
24+
\begin{itemize}
25+
\item a pandas.DataFrame which contains the dataset,
26+
\item a participant's name.
27+
\end{itemize}
28+
The function returns a dictionary of dictionaries giving the number and type of medals
29+
for each year during which the participant won medals.\\
30+
\\
31+
The keys of the main dictionary are the years of the Olympic games.\\
32+
\\
33+
In each year's dictionary, the keys are 'G', 'S', 'B' corresponding to the type of
34+
medals won (Gold, Silver, Bronze).\
35+
The innermost values correspond to the number of medals of a given type won for a given year.
36+
37+
% ================================= %
38+
\section*{Examples}
39+
% --------------------------------- %
40+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
41+
from FileLoader import FileLoader
42+
loader = FileLoader()
43+
data = loader.load('../data/athlete_events.csv')
44+
# Output
45+
Loading dataset of dimensions 271116 x 15
46+
47+
48+
from HowManyMedals import how_many_medals
49+
how_many_medals(data, 'Kjetil Andr Aamodt')
50+
# Output
51+
{1992: {'G': 1, 'S': 0, 'B': 1},
52+
1994: {'G': 0, 'S': 2, 'B': 1},
53+
1998: {'G': 0, 'S': 0, 'B': 0},
54+
2002: {'G': 2, 'S': 0, 'B': 0},
55+
2006: {'G': 1, 'S': 0, 'B': 0}}
56+
\end{minted}

module04/exercises/m04ex04.tex

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
\chapter{Exercise 04}
2+
\extitle{SpatioTemporalData}
3+
\turnindir{ex04}
4+
\exnumber{04}
5+
\exfiles{FileLoader.py, SpatioTemporalData.py}
6+
\exforbidden{None}
7+
\makeheaderfilesforbidden
8+
9+
10+
% ================================= %
11+
\section*{Objective}
12+
% --------------------------------- %
13+
The goal of this exercise is to implement a class called \texttt{SpatioTemporalData}
14+
that takes a dataset (pandas.DataFrame) as argument in its constructor
15+
and implements two methods.
16+
% ================================= %
17+
\section*{Instructions}
18+
% --------------------------------- %
19+
This exercise uses the dataset \texttt{athlete\_events.csv}.\\
20+
\\
21+
Write a class called \texttt{SpatioTemporalData} that takes a dataset
22+
(pandas.DataFrame) as argument in its constructor and implements the
23+
following methods:
24+
\begin{itemize}
25+
\item \texttt{when(location)}: takes a location as an argument and returns
26+
a list containing the years where games were held in the given location,
27+
\item \texttt{where(date)}: takes a date as an argument and returns the location
28+
where the Olympics took place in the given year.
29+
\end{itemize}
30+
31+
% ================================= %
32+
\section*{Examples}
33+
% --------------------------------- %
34+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
35+
from FileLoader import FileLoader
36+
loader = FileLoader()
37+
data = loader.load('../data/athlete_events.csv')
38+
# Output
39+
Loading dataset of dimensions 271116 x 15
40+
41+
42+
from SpatioTemporalData import SpatioTemporalData
43+
sp = SpatioTemporalData(data)
44+
sp.where(1896)
45+
# Output
46+
['Athina']
47+
48+
49+
sp.where(2016)
50+
# Output
51+
['Rio de Janeiro']
52+
53+
54+
sp.when('Athina')
55+
# Output
56+
[2004, 1906, 1896]
57+
58+
59+
sp.when('Paris')
60+
# Output
61+
[1900, 1924]
62+
\end{minted}

module04/exercises/m04ex05.tex

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
\chapter{Exercise 05}
2+
\extitle{HowManyMedalsByCountry}
3+
\turnindir{ex05}
4+
\exnumber{05}
5+
\exfiles{FileLoader.py, HowManyMedalsByCountry.py}
6+
\exforbidden{None}
7+
\makeheaderfilesforbidden
8+
9+
10+
% ================================= %
11+
\section*{Objective}
12+
% --------------------------------- %
13+
The goal of this exercise is to write a function that returns a
14+
dictionary of dictionaries giving the number and types of medals for
15+
each competition where a given country delegation earned medals.
16+
17+
% ================================= %
18+
\section*{Instructions}
19+
% --------------------------------- %
20+
This exercise uses the following dataset: \texttt{athlete\_events.csv}\\
21+
\\
22+
Write a function \texttt{how\_many\_medals\_by\_country} that takes two arguments:
23+
\begin{itemize}
24+
\item a pandas.DataFrame which contains the dataset
25+
\item a country name.
26+
\end{itemize}
27+
The function returns a dictionary of dictionaries giving the number and
28+
types of medals for each competition where the country delegation earned medals.\\
29+
\\
30+
The keys of the main dictionary are the Olympic games' years. In each
31+
year's dictionary, the keys are 'G', 'S', 'B' corresponding to the
32+
types of medals won.
33+
\\
34+
Duplicated medals per team games should be handled and not counted twice.\\
35+
\\
36+
Hint: You may find this list to be of some use.
37+
38+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
39+
team_sports = ['Basketball', 'Football', 'Tug-Of-War', 'Badminton', 'Sailing',
40+
'Handball', 'Water Polo', 'Hockey', 'Rowing', 'Bobsleigh', 'Softball',
41+
'Volleyball', 'Synchronized Swimming', 'Baseball', 'Rugby Sevens',
42+
'Rugby', 'Lacrosse', 'Polo']
43+
\end{minted}
44+
45+
% ================================= %
46+
\section*{Examples}
47+
% --------------------------------- %
48+
\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
49+
from FileLoader import FileLoader
50+
loader = FileLoader()
51+
data = loader.load('../data/athlete_events.csv')
52+
# Output
53+
Loading dataset of dimensions 271116 x 15
54+
55+
56+
from HowManyMedalsByCountry import how_many_medals_by_country
57+
how_many_medals_by_country(data, 'Martian Federation')
58+
# Output
59+
{2192: {'G': 17, 'S': 14, 'B': 23}, 2196: {'G': 8, 'S': 21, 'B': 19}, 2200: {'G': 26, 'S': 19, 'B': 7}}
60+
\end{minted}
61+
\newline
62+
You probably guessed by now that we gave up providing real examples...\\
63+
\\
64+
If you want real examples, you can easily look online.\\
65+
\\
66+
Do beware that some medals might be awarded or removed years after the games
67+
are over, for example if a previous medallist was found to have cheated.\\
68+
\\
69+
The \texttt{athlete\_events.csv} dataset might not always take these posterior
70+
changes into account.

0 commit comments

Comments
 (0)