├── .github
└── workflows
│ ├── README.md
│ ├── make-it.yml
│ └── release-it.yml
├── .gitignore
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── assets
└── 42ai_logo.png
├── build
├── module00.pdf
├── module01.pdf
├── module02.pdf
├── module03.pdf
└── module04.pdf
├── module00
└── subject
│ ├── Makefile
│ ├── assets
│ ├── 42ai_logo.pdf
│ └── 42ai_logo.png
│ ├── en.acknowledgements.tex
│ ├── en.instructions.tex
│ ├── en.subject.pdf
│ ├── en.subject.tex
│ └── exercises
│ ├── m00ex00.tex
│ ├── m00ex01.tex
│ ├── m00ex02.tex
│ ├── m00ex03.tex
│ ├── m00ex04.tex
│ ├── m00ex05.tex
│ ├── m00ex06.tex
│ ├── m00ex07.tex
│ ├── m00ex08.tex
│ ├── m00ex09.aux
│ ├── m00ex09.tex
│ ├── m00ex10.aux
│ └── m00ex10.tex
├── module01
├── attachments
│ ├── banking_test1.py
│ ├── banking_test2.py
│ └── banking_test3.py
├── exercises
│ ├── m01ex00.tex
│ ├── m01ex01.tex
│ ├── m01ex02.tex
│ ├── m01ex03.tex
│ ├── m01ex04.tex
│ ├── m01ex05.tex
│ ├── m01ex06.tex
│ ├── m01ex07.tex
│ └── m01ex08.tex
└── subject
│ ├── Makefile
│ ├── assets
│ └── 42ai_logo.pdf
│ ├── en.acknowledgements.tex
│ ├── en.instructions.tex
│ ├── en.subject.pdf
│ └── en.subject.tex
├── module02
├── attachments
│ ├── bad.csv
│ └── good.csv
└── subject
│ ├── Makefile
│ ├── assets
│ └── 42ai_logo.pdf
│ ├── en.acknowledgements.tex
│ ├── en.instructions.tex
│ ├── en.subject.pdf
│ ├── en.subject.tex
│ └── exercises
│ ├── m02ex00.tex
│ ├── m02ex01.tex
│ ├── m02ex02.tex
│ ├── m02ex03.tex
│ ├── m02ex04.tex
│ └── m02ex05.tex
├── module03
├── assets
│ ├── 42AIlogo.png
│ ├── elon_blue.png
│ ├── elon_blue_2.png
│ ├── elon_canaGAN.png
│ ├── elon_canaGAN_2.png
│ ├── elon_canaGAN_test.png
│ ├── elon_celluloid.png
│ ├── elon_celluloid2.png
│ ├── elon_celluloid_2.png
│ ├── elon_green.png
│ ├── elon_green_2.png
│ ├── elon_inverted.png
│ ├── elon_inverted_2.png
│ ├── elon_red.png
│ └── elon_red_2.png
├── attachments
│ ├── 42AI.png
│ ├── elon_canaGAN.png
│ └── solar_system_census.csv
├── exercises
│ ├── m03ex00.tex
│ ├── m03ex01.tex
│ ├── m03ex02.tex
│ ├── m03ex03.tex
│ └── m03ex04.tex
└── subject
│ ├── Makefile
│ ├── assets
│ ├── 42ai_logo.pdf
│ ├── capture_display_img.png
│ ├── elon_blue.png
│ ├── elon_canaGAN.png
│ ├── elon_celluloid.png
│ ├── elon_green.png
│ ├── elon_inverted.png
│ └── elon_red.png
│ ├── en.acknowledgements.tex
│ ├── en.instructions.tex
│ ├── en.subject.pdf
│ └── en.subject.tex
├── module04
├── attachments
│ └── athlete_events.csv
├── exercises
│ ├── m04ex00.tex
│ ├── m04ex01.tex
│ ├── m04ex02.tex
│ ├── m04ex03.tex
│ ├── m04ex04.tex
│ ├── m04ex05.tex
│ ├── m04ex06.tex
│ └── m04ex07.tex
└── subject
│ ├── Makefile
│ ├── assets
│ ├── 42ai_logo.pdf
│ ├── ex06_box_plot.png
│ ├── ex06_density.png
│ ├── ex06_histogram.png
│ └── ex06_pair_plot.png
│ ├── en.acknowledgements.tex
│ ├── en.instructions.tex
│ ├── en.subject.pdf
│ └── en.subject.tex
├── resources
├── .gitignore
└── latex
│ ├── 42-crea-en.cls
│ ├── 42-crea-fr.cls
│ ├── 42-en.cls
│ ├── 42-es.cls
│ ├── 42-fr.cls
│ ├── 42-hy.cls
│ ├── 42-it.cls
│ ├── 42-ja.cls
│ ├── 42-ko.cls
│ ├── 42-nl.cls
│ ├── 42-pt.cls
│ ├── 42-ro.cls
│ ├── 42_logo.pdf
│ ├── Makefile.LaTeX
│ ├── Makefile.template
│ ├── atbeginend.sty
│ ├── back.pdf
│ ├── dark-42-fr.cls
│ ├── dark-42_logo.pdf
│ ├── dark-back.pdf
│ ├── helphint.pdf
│ ├── info.pdf
│ ├── minted.sty
│ ├── multirow.sty
│ ├── tocloft.sty
│ └── warn.pdf
└── version
/.github/workflows/README.md:
--------------------------------------------------------------------------------
1 | # About 42AI actions
2 |
3 | ## make-it.yml
4 |
5 | > On any push, regardless of the branch, this action will attempt to build the PDFs.
6 |
7 | ## release-it.yml
8 |
9 | > Branch : MASTER
10 |
11 | For any push on MASTER branch, this action will build the PDFs and publish a new release for the project.
12 |
13 | > NB: For the new release to appear, uploaded code must contain a non-existing VERSION.
14 | > Adapt the content of the file `/version` accordingly.
15 |
16 |
--------------------------------------------------------------------------------
/.github/workflows/make-it.yml:
--------------------------------------------------------------------------------
1 | name: make-it
2 |
3 | on: [push]
4 |
5 | jobs:
6 | make-it:
7 | permissions:
8 | contents: write
9 | runs-on: ubuntu-latest
10 | steps:
11 | - name: Checkout repository
12 | uses: actions/checkout@v4
13 | - name: Install LaTex utilities
14 | run: sudo apt update && sudo apt-get install -y texlive-full
15 | - name: Get version from file
16 | id: get_version
17 | run: echo "VERSION=version/$(cat version)" >> $GITHUB_ENV
18 | - name: Name release from version
19 | id: get_release
20 | run: echo "RELEASE=release_$(cat version)" >> $GITHUB_ENV
21 | - name: Build PDFs
22 | run: make
23 | - name: Upload PDFs archives
24 | uses: actions/upload-artifact@v4
25 | with:
26 | name: modules.pdf
27 | path: |
28 | build/module00.pdf
29 | build/module01.pdf
30 | build/module02.pdf
31 | build/module03.pdf
32 | build/module04.pdf
--------------------------------------------------------------------------------
/.github/workflows/release-it.yml:
--------------------------------------------------------------------------------
1 | name: release-it
2 |
3 | on: [push]
4 |
5 | jobs:
6 | release-it:
7 | permissions:
8 | contents: write
9 | runs-on: ubuntu-latest
10 | if: contains(github.ref, 'master')
11 | steps:
12 | - name: Checkout repository
13 | uses: actions/checkout@v4
14 | - name: Install LaTex utilities
15 | run: sudo apt update && sudo apt-get install -y texlive-full
16 | - name: Get version from file
17 | id: get_version
18 | run: echo "VERSION=version/$(cat version)" >> $GITHUB_ENV
19 | - name: Name release from version
20 | id: get_release
21 | run: echo "RELEASE=release_$(cat version)" >> $GITHUB_ENV
22 | - name: Build PDFs
23 | run: make
24 | - name: Upload PDFs archives
25 | uses: actions/upload-artifact@v4
26 | with:
27 | name: modules.pdf
28 | path: |
29 | build/module00.pdf
30 | build/module01.pdf
31 | build/module02.pdf
32 | build/module03.pdf
33 | build/module04.pdf
34 | - name: Bundle Release
35 | uses: softprops/action-gh-release@v2
36 | with:
37 | files: |
38 | build/module00.pdf
39 | build/module01.pdf
40 | build/module02.pdf
41 | build/module03.pdf
42 | build/module04.pdf
43 | name: ${{env.RELEASE}}
44 | tag_name: ${{env.VERSION}}
45 | make_latest: true
46 | body_path: CHANGELOG.md
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Personnal
2 | *.zip
3 |
4 | # VSCode
5 | *.vscode/
6 |
7 | # Byte-compiled / optimized / DLL files
8 | __pycache__/
9 | *.py[cod]
10 | *$py.class
11 |
12 | # C extensions
13 | *.so
14 |
15 | # Latex compilation files
16 | *.fdb_latexmk
17 | *.fls
18 | *.pdf.version
19 |
20 | # Distribution / packaging
21 | .Python
22 | develop-eggs/
23 | dist/
24 | downloads/
25 | eggs/
26 | .eggs/
27 | lib/
28 | lib64/
29 | parts/
30 | sdist/
31 | var/
32 | wheels/
33 | *.egg-info/
34 | .installed.cfg
35 | *.egg
36 | MANIFEST
37 |
38 | # PyInstaller
39 | # Usually these files are written by a python script from a template
40 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
41 | *.manifest
42 | *.spec
43 |
44 | # Installer logs
45 | pip-log.txt
46 | pip-delete-this-directory.txt
47 |
48 | # Unit test / coverage reports
49 | htmlcov/
50 | .tox/
51 | .coverage
52 | .coverage.*
53 | .cache
54 | nosetests.xml
55 | coverage.xml
56 | *.cover
57 | .hypothesis/
58 | .pytest_cache/
59 |
60 | # Translations
61 | *.mo
62 | *.pot
63 |
64 | # Django stuff:
65 | *.log
66 | local_settings.py
67 | db.sqlite3
68 |
69 | # Flask stuff:
70 | instance/
71 | .webassets-cache
72 |
73 | # Scrapy stuff:
74 | .scrapy
75 |
76 | # Sphinx documentation
77 | docs/_build/
78 |
79 | # PyBuilder
80 | target/
81 |
82 | # Jupyter Notebook
83 | .ipynb_checkpoints
84 |
85 | # pyenv
86 | .python-version
87 |
88 | # celery beat schedule file
89 | celerybeat-schedule
90 |
91 | # SageMath parsed files
92 | *.sage.py
93 |
94 | # Environments
95 | .env
96 | .venv
97 | env/
98 | venv/
99 | ENV/
100 | env.bak/
101 | venv.bak/
102 |
103 | # Spyder project settings
104 | .spyderproject
105 | .spyproject
106 |
107 | # Rope project settings
108 | .ropeproject
109 |
110 | # mkdocs documentation
111 | /site
112 |
113 | # mypy
114 | .mypy_cache/
115 |
116 | # Mac Os
117 | .DS_Store
118 | .Spotlight-V100
119 | .Trashes
120 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | - One file per exercise
2 | - Indentation fixes
3 | - Makefile update to clean latex compilation files
4 |
5 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at contact@42ai.fr. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM blang/latex:ubuntu
2 |
3 | RUN pwd
4 |
5 | COPY . /data/bootcamp_python
6 |
7 | WORKDIR /data/bootcamp_python
8 |
9 | RUN pwd\
10 | && make \
11 | && ls -l . \
12 | && ls -l module00/subject
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | DIRECTORIES = module00 \
2 | module01 \
3 | module02 \
4 | module03 \
5 | module04
6 |
7 | TARGETS_DIRS = $(DIRECTORIES:%=%/subject/en.subject.pdf)
8 |
9 | TARGETS = $(DIRECTORIES:%=%.pdf)
10 |
11 | all: clean dirs
12 |
13 | %.pdf:
14 | @echo "We are taking care of: $@"
15 | @$(MAKE) -C $(shell dirname $@)
16 | @$(MAKE) clean -C $(shell dirname $@)
17 | cp $@ build/$(shell dirname `dirname $@`).pdf
18 |
19 | dirs: $(TARGETS_DIRS)
20 |
21 |
22 | build_pdfs:
23 | sudo docker run -v "$(shell pwd)/build:/data/bootcamp_python/build" -i latex_build_py make
24 |
25 | build_builder:
26 | sudo docker build -t latex_build_py .
27 |
28 | clean:
29 | rm -rf $(TARGETS) $(TARGETS_DIRS)
30 |
31 | debug:
32 | echo $(TARGETS_DIRS)
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Bootcamp Python
7 |
8 |
9 | One week to learn Python for Machine Learning :rocket:
10 |
11 |
12 |
13 | ### Table of Contents
14 |
15 | - [Download](#download)
16 | - [Curriculum](#curriculum)
17 | - [Module00 - Basics 1 - Eleven Commandments](#module00---basics-1---eleven-commandments)
18 | - [Module01 - Basics 2](#module01---basics-2)
19 | - [Module02 - Basics 3](#module02---basics-3)
20 | - [Module03 - Numpy](#module03---numpy)
21 | - [Module04 - Pandas](#module04---pandas)
22 | - [Acknowledgements](#acknowledgements)
23 | - [Contributors](#contributors)
24 | - [Beta-testers](#beta-testers)
25 | - [Thanks to Ilyes and Kévin for the PR](#thanks-to-ilyes-and-kévin-for-the-pr)
26 |
27 | >This project is a Python programming and Machine Learning bootcamp created by [42 AI](http://www.42ai.fr).
28 | >
29 | >No prior Python programming or Machine Learning experience is required!
30 |
31 | Your mission, should you choose to accept it, is to learn some of the essential knowledge for Machine Learning, Data Science and statistics, in a single week.
32 |
33 | You will start with the basics of **Python** and then get acquainted with some libraries that are invaluable to any programmer interested in the field of AI or data science.
34 |
35 | 42 Artificial Intelligence is a student organization of the Paris campus of the school 42. Our purpose is to foster discussion, learning, and interest in the field of artificial intelligence, by organizing various activities such as lectures and workshops.
36 |
37 | ## Download
38 |
39 | The pdf files of each module can be downloaded from our realease page:
40 | [https://github.com/42-AI/bootcamp_python/releases](https://github.com/42-AI/bootcamp_python/releases)
41 |
42 | ## Curriculum
43 |
44 | ### Module00 - Basics 1 - Eleven Commandments
45 | **Let's get started with the Python language!** :snake:
46 | > Basic setup, variables, types, functions, ...
47 |
48 | ### Module01 - Basics 2
49 | **Get acquainted with object-oriented programming and much more.**
50 | > Objects, cast, inheritance, built-in functions, generator, construtors, iterator, ...
51 |
52 | ### Module02 - Basics 3
53 | **Continue practicing with more advanced Python programming exercises.**
54 | > Decorators, multiprocessing, lambda, build package, ...
55 |
56 | ### Module03 - Numpy
57 | **Learn how to use the Numpy library, manipulate multidimensional arrays and perform complex mathematical operations on matrices!**
58 | > Numpy array, slicing, stacking, dimensions, broadcasting, normalization, etc...
59 |
60 | ### Module04 - Pandas
61 | **Time to use a Python library that will allow you to manipulate dataframes.**
62 | > Pandas! And Bamboos! :panda_face:
63 |
64 | ## Acknowledgements
65 |
66 | ### Contributors
67 |
68 | * Amric Trudel (amric@42ai.fr)
69 | * Maxime Choulika (maxime@42ai.fr)
70 | * Baptiste Lefeuvre (blefeuvr@student.42.fr)
71 | * Mathilde Boivin (mboivin@student.42.fr)
72 | * Tristan Duquesne (tduquesn@student.42.fr)
73 | * Pierre Peigné (ppeigne@student.42.fr)
74 | * Quentin Feuillade Montixi (qfeuilla@student.42.fr)
75 | * Mathieu Perez (mathieu.perez@42ai.fr)
76 |
77 | ### Beta-testers
78 |
79 | * Barthélémy Leveque (bleveque@student.42.fr)
80 | * Remy Oster (roster@student.42.fr)
81 | * Quentin Bragard (qbragard@student.42.fr)
82 | * Marie Dufourq (madufour@student.42.fr)
83 | * Adrien Vardon (advardon@student.42.fr)
84 |
85 | ### Thanks to Ilyes and Kévin for the PR
86 |
87 | * Ilyes Bouchlaghem (ibouchla@student.42.fr)
88 | * Kévin Azoulay-Dessus (kevazoul@student.42lyon.fr)
89 |
--------------------------------------------------------------------------------
/assets/42ai_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/assets/42ai_logo.png
--------------------------------------------------------------------------------
/build/module00.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/build/module00.pdf
--------------------------------------------------------------------------------
/build/module01.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/build/module01.pdf
--------------------------------------------------------------------------------
/build/module02.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/build/module02.pdf
--------------------------------------------------------------------------------
/build/module03.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/build/module03.pdf
--------------------------------------------------------------------------------
/build/module04.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/build/module04.pdf
--------------------------------------------------------------------------------
/module00/subject/Makefile:
--------------------------------------------------------------------------------
1 | # List the pdf's to build. foo.tex will produce foo.pdf
2 | TARGETS = en.subject.pdf
3 |
4 | # List the files included in the slides
5 | DEPS =
6 |
7 | # Relative path to the LaTeX documentclass setup files
8 | # Adapt as needed
9 | # RELPATH = $(shell git rev-parse --show-toplevel)/resources/latex/
10 | # RELPATH for github actions:
11 | RELPATH = $(shell pwd)/../../resources/latex/
12 |
13 | # You should not touch this either
14 | include $(RELPATH)/Makefile.LaTeX
15 |
16 |
17 |
--------------------------------------------------------------------------------
/module00/subject/assets/42ai_logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module00/subject/assets/42ai_logo.pdf
--------------------------------------------------------------------------------
/module00/subject/assets/42ai_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module00/subject/assets/42ai_logo.png
--------------------------------------------------------------------------------
/module00/subject/en.acknowledgements.tex:
--------------------------------------------------------------------------------
1 | \section*{Contact}
2 | % --------------------------------- %
3 | You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\
4 | \newline
5 | Thank you for attending 42AI's Python Bootcamp module00 !
6 |
7 | % ================================= %
8 | \section*{Acknowledgements}
9 | % --------------------------------- %
10 | The Python bootcamp is the result of a collective work, for which we would like to thank:
11 | \begin{itemize}
12 | \item Maxime Choulika (cmaxime),
13 | \item Pierre Peigné (ppeigne, pierre@42ai.fr),
14 | \item Matthieu David (mdavid, matthieu@42ai.fr),
15 | \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr)
16 | \item Mathieu Perez (maperez, mathieu.perez@42ai.fr)
17 | \end{itemize}
18 | who supervised the creation, the enhancement of the bootcamp and this present transcription.
19 |
20 | \begin{itemize}
21 | \item Louis Develle (ldevelle, louis@42ai.fr)
22 | \item Augustin Lopez (aulopez)
23 | \item Luc Lenotre (llenotre)
24 | \item Owen Roberts (oroberts)
25 | \item Thomas Flahault (thflahau)
26 | \item Amric Trudel (amric@42ai.fr)
27 | \item Baptiste Lefeuvre (blefeuvr@student.42.fr)
28 | \item Mathilde Boivin (mboivin@student.42.fr)
29 | \item Tristan Duquesne (tduquesn@student.42.fr)
30 | \end{itemize}
31 | for your investment in the creation and development of these modules.
32 |
33 | \begin{itemize}
34 | \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps !
35 | \end{itemize}
36 |
37 | \vfill
38 | \doclicenseThis
--------------------------------------------------------------------------------
/module00/subject/en.instructions.tex:
--------------------------------------------------------------------------------
1 | %******************************************************************************%
2 | % %
3 | % Common Instructions %
4 | % for Python Projects %
5 | % %
6 | %******************************************************************************%
7 |
8 | \chapter{Common Instructions}
9 | \begin{itemize}
10 | \item The version of Python recommended to use is 3.7, you can
11 | check the version of Python with the following command: \texttt{python -V}
12 |
13 | \item The norm: during this bootcamp, it is recommended to follow the
14 | \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory.
15 | You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which
16 | is a tool to check your Python code.
17 | \item The function \texttt{eval} is never allowed.
18 | \item The exercises are ordered from the easiest to the hardest.
19 | \item Your exercises are going to be evaluated by someone else,
20 | so make sure that your variable names and function names are appropriate and civil.
21 | \item Your manual is the internet.
22 |
23 | \item If you are a student from 42, you can access our Discord server
24 | on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your
25 | questions to your peers in the dedicated Bootcamp channel.
26 |
27 | \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}.
28 |
29 | \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}.
30 |
31 | \item We encourage you to create test programs for your
32 | project even though this work \textbf{won't have to be
33 | submitted and won't be graded}. It will give you a chance
34 | to easily test your work and your peers’ work. You will find
35 | those tests especially useful during your defence. Indeed,
36 | during defence, you are free to use your tests and/or the
37 | tests of the peer you are evaluating.
38 |
39 | \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\
40 | You can tell us more about your experience with this module by filling \href{https://forms.gle/89TZJDARdgZfghRPA}{this form}.\\
41 | Thank you in advance and good luck for this bootcamp !
42 |
43 | \end{itemize}
--------------------------------------------------------------------------------
/module00/subject/en.subject.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module00/subject/en.subject.pdf
--------------------------------------------------------------------------------
/module00/subject/en.subject.tex:
--------------------------------------------------------------------------------
1 | % vim: set ts=4 sw=4 tw=80 noexpandtab:
2 |
3 | \documentclass{42-en}
4 |
5 | %******************************************************************************%
6 | % %
7 | % Prologue %
8 | % %
9 | %******************************************************************************%
10 | \usepackage[
11 | type={CC},
12 | modifier={by-nc-sa},
13 | version={4.0},
14 | ]{doclicense}
15 | \usemintedstyle{monokai}
16 |
17 |
18 | %****************************************************************%
19 | % Re/definition of commands %
20 | %****************************************************************%
21 |
22 | \newcommand{\ailogo}[1]{\def \@ailogo {#1}}\ailogo{assets/42ai_logo.pdf}
23 |
24 | %% Redefine \maketitle
25 | \makeatletter
26 | \def \maketitle {
27 | \begin{titlepage}
28 | \begin{center}
29 | %\begin{figure}[t]
30 | %\includegraphics[height=8cm]{\@ailogo}
31 | \includegraphics[height=8cm]{assets/42ai_logo.pdf}
32 | %\end{figure}
33 | \vskip 5em
34 | {\huge \@title}
35 | \vskip 2em
36 | {\LARGE \@subtitle}
37 | \vskip 4em
38 | \end{center}
39 | %\begin{center}
40 | %\@author
41 | %\end{center}
42 | %\vskip 5em
43 | \vfill
44 | \begin{center}
45 | \emph{\summarytitle : \@summary}
46 | \end{center}
47 | \vspace{2cm}
48 | %\vskip 5em
49 | %\doclicenseThis
50 | \end{titlepage}
51 | }
52 | \makeatother
53 |
54 | \makeatletter
55 | \def \makeheaderfilesforbidden
56 | {
57 | \noindent
58 | \begin{tabularx}{\textwidth}{|X X X X|}
59 | \hline
60 | \multicolumn{1}{|>{\raggedright}m{1cm}|}
61 | {\vskip 2mm \includegraphics[height=1cm]{assets/42ai_logo.pdf}} &
62 | \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } &
63 | \multicolumn{1}{ >{\raggedleft}p{1.5cm}|}
64 | %% {\scriptsize points : \@exscore} \\ \hline
65 | {} \\ \hline
66 |
67 | \multicolumn{4}{|>{\centering}m{15cm}|}
68 | {\small \@extitle} \\ \hline
69 |
70 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
71 | {\small Turn-in directory : \ttfamily
72 | $ex\@exnumber/$ }
73 | \\ \hline
74 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
75 | {\small Files to turn in : \ttfamily \@exfiles }
76 | \\ \hline
77 |
78 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
79 | {\small Forbidden functions : \ttfamily \@exforbidden }
80 | \\ \hline
81 |
82 | %% \multicolumn{4}{|>{\raggedright}m{15cm}|}
83 | %% {\small Remarks : \ttfamily \@exnotes }
84 | %% \\ \hline
85 | \end{tabularx}
86 | %% \exnotes
87 | \exrules
88 | \exmake
89 | \exauthorize{None}
90 | \exforbidden{None}
91 | \extitle{}
92 | \exnumber{}
93 | }
94 | \makeatother
95 |
96 | \begin{document}
97 |
98 | % =============================================================================%
99 | % ===================================== %
100 |
101 | \title{Python Bootcamp - Module 00}
102 | \subtitle{Basic stuff - The Eleven Commandments}
103 | \author{}
104 | \summary{The goal of this module is to get you started with Python}
105 | \maketitle
106 | \input{en.instructions.tex}
107 | \newpage
108 | \tableofcontents
109 | \startexercices
110 | % ===================================== %
111 | % =============================================================================%
112 | %******************************************************************************%
113 | % %
114 | % Exercises %
115 | % %
116 | %******************************************************************************%
117 |
118 | % ===========================(start ex 00) %
119 | \input{exercises/m00ex00.tex}
120 | % ===========================(fin ex 00) %
121 | \newpage
122 | % ===========================(start ex 01) %
123 | \input{exercises/m00ex01.tex}
124 | % ===========================(fin ex 01) %
125 | \newpage
126 | % ===========================(start ex 02) %
127 | \input{exercises/m00ex02.tex}
128 | % ===========================(fin ex 02) %
129 | \newpage
130 | % ===========================(start ex 03) %
131 | \input{exercises/m00ex03.tex}
132 | % ===========================(fin ex 03) %
133 | \newpage
134 | % ===========================(start ex 04) %
135 | \input{exercises/m00ex04.tex}
136 | % ===========================(fin ex 04) %
137 | \newpage
138 | % ===========================(start ex 05) %
139 | \input{exercises/m00ex05.tex}
140 | % ===========================(fin ex 05) %
141 | \newpage
142 | % ===========================(start ex 06) %
143 | \input{exercises/m00ex06.tex}
144 | % ===========================(fin ex 06) %
145 | \newpage
146 | % ===========================(start ex 07) %
147 | \input{exercises/m00ex07.tex}
148 | % ===========================(fin ex 07) %
149 | \newpage
150 | % ===========================(start ex 08) %
151 | \input{exercises/m00ex08.tex}
152 | % ===========================(fin ex 08) %
153 | \newpage
154 | % ===========================(start ex 09) %
155 | \include{exercises/m00ex09.tex}
156 | % ===========================(fin ex 09) %
157 | \newpage
158 | % ===========================(start ex 10) %
159 | \include{exercises/m00ex10.tex}
160 | % ===========================(fin ex 10) %
161 | \newpage
162 | % ================================= %
163 | \input{en.acknowledgements.tex}
164 | % ================================= %
165 |
166 | \end{document}
167 |
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex00.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 00}
2 | \extitle{\$PATH}
3 | \turnindir{ex00}
4 | \exnumber{00}
5 | \exfiles{answers.txt, requirements.txt}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden\\
8 | \emph{The first thing you need to do is to install Python.}
9 | \\\\
10 | Most modern Unix-based systems have a \texttt{python} interpreter installed by default,
11 | but its version might be lower/higher than the one used for these modules.
12 | It is also possible that the default \texttt{python} command uses a version 2.x (for legacy reasons).
13 | This is obviously very confusing for a new developper.
14 | \\
15 |
16 | \begin{42console}
17 | $> python -V
18 | $> python3 -V
19 | \end{42console}
20 | \hfill \break
21 | To deal with those versions issues we will use \texttt{conda}. This program allows you to manage your Python packages and several working environments.
22 | \\\\
23 | \emph{Note: the actual requirement is to use a Python 3.7.X version. You are free to use a different program/utilities to achieve this goal. At your own risk.}
24 | \pagebreak
25 |
26 | % ===========================(Conda Manual) %
27 | \section*{Conda manual installation}
28 | \emph{Go to the next section for an automated installation.}
29 | \\\\
30 | We recommend the following path for your \texttt{conda} folder.
31 | \begin{42console}
32 | $> MYPATH="/goinfre/$USER/miniconda3"
33 | \end{42console}
34 |
35 | % ---------------------------------- %
36 | \subsection*{1. Download \& Install conda}
37 |
38 | \begin{42console}
39 | # For MAC
40 | $> curl -LO "https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh"
41 | $> sh Miniconda3-latest-MacOSX-x86_64.sh -b -p $MYPATH
42 |
43 | # For Linux
44 | $> curl -LO "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"
45 | $> sh Miniconda3-latest-Linux-x86_64.sh -b -p $MYPATH
46 | \end{42console}
47 |
48 |
49 |
50 | % ---------------------------------- %
51 | \subsection*{2. Initial configuration of conda}
52 | \begin{42console}
53 | # For zsh
54 | $> $MYPATH/bin/conda init zsh
55 | $> $MYPATH/bin/conda config --set auto_activate_base false
56 | $> source ~/.zshrc
57 |
58 | # For bash
59 | $> $MYPATH/bin/conda init bash
60 | $> $MYPATH/bin/conda config --set auto_activate_base false
61 | $> source ~/.bash_profile
62 | \end{42console}
63 |
64 |
65 |
66 | % ---------------------------------- %
67 | \subsection*{3. Create a dedicated environment for 42AI !}
68 | \begin{42console}
69 | $> conda create --name 42AI-$USER python=3.7 jupyter pandas pycodestyle numpy
70 | \end{42console}
71 |
72 |
73 |
74 | % ---------------------------------- %
75 | \subsection*{4. Check your 42AI Python environment}
76 | \begin{42console}
77 | $> conda info --envs
78 | $> conda activate 42AI-$USER
79 | $> which python
80 | $> python -V
81 | $> python -c "print('Hello World!')"
82 | \end{42console}
83 |
84 |
85 |
86 | % ---------------------------------- %
87 | \subsection*{Help !}
88 | \begin{itemize}
89 | \item \textbf{I have lost my miniconda3 folder !} Repeat step 1 and 3.
90 | \item \textbf{I have lost my home directory !} Repeat step 2.
91 | \end{itemize}
92 | \pagebreak
93 |
94 |
95 |
96 | % ===========================(Conda Auto) %
97 | \section*{Conda automated installation}
98 |
99 | Copy the following script into a file, launch it and follow the instructions. It downloads and installs miniconda in a \texttt{/goinfre} subfolder and creates a \texttt{python} environment in \texttt{conda}.
100 |
101 |
102 | \begin{42console}
103 | #!/bin/bash
104 |
105 | function which_dl {
106 | # If operating system name contains Darwnin: MacOS. Else Linux
107 | if uname -s | grep -iqF Darwin; then
108 | echo "Miniconda3-latest-MacOSX-x86_64.sh"
109 | else
110 | echo "Miniconda3-latest-Linux-x86_64.sh"
111 | fi
112 | }
113 |
114 | function which_shell {
115 | # if $SHELL contains zsh, zsh. Else Bash
116 | if echo $SHELL | grep -iqF zsh; then
117 | echo "zsh"
118 | else
119 | echo "bash"
120 | fi
121 | }
122 |
123 | function when_conda_exist {
124 | # check and install 42AI environement
125 | printf "Checking 42AI-$USER environment: "
126 | if conda info --envs | grep -iqF 42AI-$USER; then
127 | printf "\e[33mDONE\e[0m\n"
128 | else
129 | printf "\e[31mKO\e[0m\n"
130 | printf "\e[33mCreating 42AI environnment:\e[0m\n"
131 | conda update -n base -c defaults conda -y
132 | conda create --name 42AI-$USER python=3.7 jupyter numpy pandas pycodestyle -y
133 | fi
134 | }
135 |
136 | function set_conda {
137 | MINICONDA_PATH="/goinfre/$USER/miniconda3"
138 | CONDA=$MINICONDA_PATH"/bin/conda"
139 | PYTHON_PATH=$(which python)
140 | REQUIREMENTS="jupyter numpy pandas pycodestyle"
141 | SCRIPT=$(which_dl)
142 | MY_SHELL=$(which_shell)
143 | DL_LINK="https://repo.anaconda.com/miniconda/"$SCRIPT
144 | DL_LOCATION="/tmp/"
145 |
146 | printf "Checking conda: "
147 | TEST=$(conda -h 2>/dev/null)
148 | if [ $? == 0 ] ; then
149 | printf "\e[32mOK\e[0m\n"
150 | when_conda_exist
151 | return
152 | fi
153 | printf "\e[31mKO\e[0m\n"
154 | if [ ! -f $DL_LOCATION$SCRIPT ]; then
155 | printf "\e[33mDonwloading installer:\e[0m\n"
156 | cd $DL_LOCATION
157 | curl -LO $DL_LINK
158 | cd -
159 | fi
160 | printf "\e[33mInstalling conda:\e[0m\n"
161 | sh $DL_LOCATION$SCRIPT -b -p $MINICONDA_PATH
162 | printf "\e[33mConda initial setup:\e[0m\n"
163 | $CONDA init $MY_SHELL
164 | $CONDA config --set auto_activate_base false
165 |
166 | printf "\e[33mCreating 42AI-$USER environnment:\e[0m\n"
167 | $CONDA update -n base -c defaults conda -y
168 | $CONDA create --name 42AI-$USER python=3.7 jupyter numpy pandas pycodestyle -y
169 | printf "\e[33mLaunch the following command or restart your shell:\e[0m\n"
170 | if [ $MY_SHELL == "zsh" ]; then
171 | printf "\tsource ~/.zshrc\n"
172 | else
173 | printf "\tsource ~/.bash_profile\n"
174 | fi
175 | }
176 |
177 | set_conda
178 | \end{42console}
179 | \hfill \break
180 | Don't forget to check your 42AI Python environment !
181 | \begin{42console}
182 | conda info --envs
183 | conda activate 42AI-$USER
184 | which python
185 | python -V
186 | python -c "print('Hello World!')"
187 | \end{42console}
188 |
189 | % =================================(Question) %
190 | \section*{(Finally) getting started}
191 |
192 | Now that your setup is ready to run, here are a few questions that need to be solved using \texttt{python}, \texttt{pip} or \texttt{conda}. Save your answers in a file \texttt{answers.txt} (one answer per line and per question), and check them with your peers.\\\\
193 | Find the commands to:
194 | \begin{itemize}
195 | \item Output a list of installed packages and their versions.
196 | \item Show the package metadata of \texttt{numpy}.
197 | \item Remove the package \texttt{numpy}.
198 | \item (Re)install the package \texttt{numpy}.
199 | \item Freeze your \texttt{python} packages and their versions in a \texttt{requirements.txt} file you have to turn-in.
200 | \end{itemize}
201 |
202 |
203 |
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex01.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 01}
2 | \extitle{Rev Alpha}
3 | \turnindir{ex01}
4 | \exnumber{01}
5 | \exfiles{exec.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 | \newline
9 | Make a program that takes a string as argument, reverses it, swaps its letters case and prints the result.
10 |
11 | \begin{itemize}
12 | \item If more than one argument is provided, merge them into a single string with each argument separated by a single space character.
13 | \item If no argument is provided, do nothing or print an usage.
14 | \end{itemize}
15 | % --------------------------------- %
16 | \section*{Examples}
17 |
18 | \begin{42console}
19 | $> python3 exec.py 'Hello World!' | cat -e
20 | !DLROw OLLEh$
21 | $>
22 | $> python3 exec.py 'Hello' 'my Friend' | cat -e
23 | DNEIRf YM OLLEh$
24 | $>
25 | $> python3 exec.py
26 | $>
27 | \end{42console}
28 |
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex02.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 02}
2 | \extitle{The Odd, the Even and the Zero}
3 | \turnindir{ex02}
4 | \exnumber{02}
5 | \exfiles{whois.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 | Make a program that takes a number as argument, checks whether it is odd, even or zero, and prints the result.
9 | \begin{itemize}
10 | \item If more than one argument is provided or if the argument is not an integer, print an error message.
11 | \item If no argument is provided, do nothing or print an usage.
12 | \end{itemize}
13 |
14 | % --------------------------------- %
15 | \section*{Examples}
16 | \begin{42console}
17 | $> python3 whois.py 12
18 | I'm Even.
19 | $>
20 | $> python3 whois.py 3
21 | I'm Odd.
22 | $>
23 | $> python3 whois.py
24 | $>
25 | $> python3 whois.py 0
26 | I'm Zero.
27 | $>
28 | $> python3 whois.py Hello
29 | AssertionError: argument is not an integer
30 | $>
31 | $> python3 whois.py 12 3
32 | AssertionError: more than one argument is provided
33 | $>
34 | \end{42console}
35 |
36 | \hint{
37 | No bonus point to be gained from a complex error management system. Keep it simple.
38 | }
39 |
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex03.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 03}
2 | \extitle{Functional file}
3 | \turnindir{ex03}
4 | \exnumber{03}
5 | \exfiles{count.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 | \section*{Part 1. text\_analyzer}
9 | Create a function called \texttt{text\_analyzer} that takes a single string argument
10 | and displays the total number of printable characters, and respectively : the number of upper-case characters, lower-case characters, punctuation characters and spaces.
11 | \begin{itemize}
12 | \item If \texttt{None} or nothing is provided, the user is prompted to provide a string.
13 | \item If the argument is not a string, print an error message.
14 | \item This function must have a \texttt{docstring} explaning its behavior.
15 | \end{itemize}
16 | Test your function within the \texttt{python} console
17 |
18 | % --------------------------------- %
19 | \subsection*{Examples}
20 | \begin{42console}
21 | $> python3
22 | >>> from count import text_analyzer
23 | >>> text_analyzer("Python 2.0, released 2000, introduced
24 | features like List comprehensions and a garbage collection
25 | system capable of collecting reference cycles.")
26 | The text contains 143 printable character(s):
27 | - 2 upper letter(s)
28 | - 113 lower letter(s)
29 | - 4 punctuation mark(s)
30 | - 18 space(s)
31 | >>> text_analyzer("Python is an interpreted, high-level,
32 | general-purpose programming language. Created by Guido van
33 | Rossum and first released in 1991, Python's design philosophy
34 | emphasizes code readability with its notable use of significant
35 | whitespace.")
36 | The text contains 234 printable character(s):
37 | - 5 upper letter(s)
38 | - 187 lower letter(s)
39 | - 8 punctuation mark(s)
40 | - 30 space(s)
41 | >>> text_analyzer()
42 | What is the text to analyze?
43 | >> Hello World!
44 | The text contains 12 printable character(s):
45 | - 2 upper letter(s)
46 | - 8 lower letter(s)
47 | - 1 punctuation mark(s)
48 | - 1 space(s)
49 | >>> text_analyzer(42)
50 | AssertionError: argument is not a string
51 | >>> print(text_analyzer.__doc__)
52 |
53 | This function counts the number of upper characters, lower characters,
54 | punctuation and spaces in a given text.
55 | \end{42console}
56 |
57 | \hint{
58 | Python has a lot of very convenient built-in functions and methods. Do some research, you do not have to reivent the wheel !
59 | }
60 |
61 | % ================================= %
62 | \section*{Part 2. \_\_name\_\_==\_\_main\_\_}
63 |
64 | In the previous part, you wrote a function that can be used in the console or in another file when imported.
65 | Without changing this behavior, update your file so it can also be launched as a standalone program.
66 |
67 | \begin{itemize}
68 | \item If more than one argument is provided to the program, print an error message.
69 | \item Otherwise, use the \texttt{text\_analyzer} function.
70 | \end{itemize}
71 |
72 | % --------------------------------- %
73 | \subsection*{Examples}
74 | \begin{42console}
75 | $> python3 count.py 'Hello World!'
76 | The text contains 12 character(s):
77 | - 2 upper letter(s)
78 | - 8 lower letter(s)
79 | - 1 punctuation mark(s)
80 | - 1 space(s)
81 | $> python3
82 | >>> from count import text_analyzer
83 | >>> text_analyzer("Hello World!")
84 | The text contains 12 character(s):
85 | - 2 upper letter(s)
86 | - 8 lower letter(s)
87 | - 1 punctuation mark(s)
88 | - 1 space(s)
89 | \end{42console}
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex04.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 04}
2 | \extitle{Elementary}
3 | \turnindir{ex04}
4 | \exnumber{04}
5 | \exfiles{operations.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden\\
8 | Write a program that takes two integers A and B as arguments and prints the result of the following operations:
9 | \newline
10 | \begin{42console}
11 | Sum: A+B
12 | Difference: A-B
13 | Product: A*B
14 | Quotient: A/B
15 | Remainder: A%B
16 | \end{42console}
17 |
18 | \begin{itemize}
19 | \item If more or less than two arguments are provided or if one of the arguments is not an integer, print an error message.
20 | \item If no argument is provided, do nothing or print an usage.
21 | \item If an operation is impossible, print an error message instead of a numerical result.
22 | \end{itemize}
23 |
24 | % ================================= %
25 | \section*{Examples}
26 | \begin{42console}
27 | $> python3 operations.py 10 3
28 | Sum: 13
29 | Difference: 7
30 | Product: 30
31 | Quotient: 3.3333...
32 | Remainder: 1
33 | $>
34 | $> python3 operations.py 42 10
35 | Sum: 52
36 | Difference: 32
37 | Product: 420
38 | Quotient: 4.2
39 | Remainder: 2
40 | $>
41 | $> python3 operations.py 1 0
42 | Sum: 1
43 | Difference: 1
44 | Product: 0
45 | Quotient: ERROR (division by zero)
46 | Remainder: ERROR (modulo by zero)
47 | $>
48 | $> python3 operations.py
49 | Usage: python operations.py
50 | Example:
51 | python operations.py 10 3
52 | $>
53 | $> python3 operations.py 12 10 5
54 | AssertionError: too many arguments
55 | $>
56 | $> python3 operations.py "one" "two"
57 | AssertionError: only integers
58 | $>
59 | \end{42console}
60 |
61 | \hint{
62 | No bonus point to be gained from handling decimal point or scientific notation. Keep it simple.
63 | }
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex05.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 05}
2 | \extitle{The right format}
3 | \turnindir{ex05}
4 | \exnumber{05}
5 | \exfiles{kata00.py, kata01.py, kata02.py, kata03.py, kata04.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 | Let's get familiar with the useful concept of \textbf{string formatting} through a kata series.\\
9 | \newline
10 | Each exercice will provide you with a \texttt{kata} variable. This variable can be modified to a certain extent: your program must react accordingly.
11 | % ================================= %
12 | \section*{kata00}
13 | The \texttt{kata} variable is always a tuple and can only be filled with integers.
14 | \begin{42console}
15 | # Put this at the top of your kata00.py file
16 | kata = (19,42,21)
17 | \end{42console}
18 | Write a program that displays this variable content according to the format shown below:
19 |
20 | \begin{42console}
21 | $> python3 kata00.py
22 | The 3 numbers are: 19, 42, 21
23 | $>
24 | \end{42console}
25 |
26 | % ================================= %
27 | \section*{kata01}
28 |
29 | The \texttt{kata} variable is always a dictionary and can only be filled with strings.
30 |
31 | \begin{42console}
32 | # Put this at the top of your kata01.py file
33 | kata = {
34 | 'Python': 'Guido van Rossum',
35 | 'Ruby': 'Yukihiro Matsumoto',
36 | 'PHP': 'Rasmus Lerdorf',
37 | }
38 | \end{42console}
39 | Write a program that displays this variable content according to the format shown below:
40 |
41 | \begin{42console}
42 | $> python3 kata01.py
43 | Python was created by Guido van Rossum
44 | Ruby was created by Yukihiro Matsumoto
45 | PHP was created by Rasmus Lerdorf
46 | $>
47 | \end{42console}
48 |
49 | % ================================= %
50 | \section*{kata02}
51 |
52 | 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.
53 |
54 | \begin{42console}
55 | # Put this at the top of your kata02.py file
56 | kata = (2019, 9, 25, 3, 30)
57 | \end{42console}
58 | Write a program that displays this variable content according to the format shown below:
59 |
60 | \begin{42console}
61 | $> python3 kata02.py | cat -e
62 | 09/25/2019 03:30$
63 | $> python3 kata02.py | wc -c
64 | 17
65 | $>
66 | \end{42console}
67 |
68 | % ================================= %
69 | \section*{kata03}
70 |
71 | The \texttt{kata} variable is always a string whose length is not higher than 42.
72 |
73 | \begin{42console}
74 | # Put this at the top of your kata03.py file
75 | kata = "The right format"
76 | \end{42console}
77 | Write a program that displays this variable content according to the format shown below:
78 |
79 | \begin{42console}
80 | $> python3 kata03.py | cat -e
81 | --------------------------The right format%
82 | $> python3 kata03.py | wc -c
83 | 42
84 | $>
85 | \end{42console}
86 |
87 | % ================================= %
88 | \section*{kata04}
89 |
90 | The \texttt{kata} variable is always a tuple that contains, in the following order:
91 | \begin{itemize}
92 | \item 2 non-negative integers containing up to 2 digits
93 | \item 1 decimal
94 | \item 1 integer
95 | \item 1 decimal
96 | \end{itemize}
97 |
98 | \begin{42console}
99 | # Put this at the top of your kata04.py file
100 | kata = (0, 4, 132.42222, 10000, 12345.67)
101 | \end{42console}
102 | Write a program that displays this variable content according to the format shown below:
103 |
104 | \begin{42console}
105 | $> python3 kata04.py
106 | module_00, ex_04 : 132.42, 1.00e+04, 1.23e+04
107 | $> python3 kata04.py | cut -c 10,18
108 | ,:
109 | \end{42console}
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex06.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 06}
2 | \extitle{A recipe}
3 | \turnindir{ex06}
4 | \exnumber{06}
5 | \exfiles{recipe.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 | % ================================= %
10 | \section*{Part 1: Nested Dictionaries}
11 |
12 | Create a dictionary called \texttt{cookbook}. You will use this \texttt{cookbook} to store recipes.
13 | \\\\
14 | A recipe is a \textbf{dictionary} that stores (at least) 3 key-value pairs:
15 | \begin{itemize}
16 | \item ''ingredients": a \textbf{list of strings} containing the list of ingredients
17 | \item "meal": a \textbf{string} representing the type of meal
18 | \item "prep\_time": a \textbf{non-negative integer} representing a preparation time in minutes
19 | \end{itemize}
20 | In the \texttt{cookbook}, the \textbf{key} to a recipe is the recipe's name.
21 | \\
22 | Initialize your \texttt{cookbook} with 3 recipes:
23 | \begin{itemize}
24 | \item The Sandwich's ingredients are \textit{ham}, \textit{bread}, \textit{cheese} and \textit{tomatoes}.
25 | It is a \textit{lunch} and it takes $10$ minutes of preparation.
26 | \item The Cake's ingredients are \textit{flour}, \textit{sugar} and \textit{eggs}.
27 | It is a \textit{dessert} and it takes $60$ minutes of preparation.
28 | \item The Salad's ingredients are \textit{avocado}, \textit{arugula}, \textit{tomatoes} and \textit{spinach}.
29 | It is a \textit{lunch} and it takes $15$ minutes of preparation.
30 | \end{itemize}
31 |
32 | % ================================= %
33 | \newpage
34 | \section*{Part 2: A Handful of Helpful Functions}
35 |
36 | Create a series of useful functions to handle your \texttt{cookbook}:
37 |
38 | \begin{enumerate}
39 | \item A function that prints all recipe names.
40 | \item A function that takes a recipe name and prints its details.
41 | \item A function that takes a recipe name and delete it.
42 | \item A function that adds a recipe from user input. You will need a name, a list of ingredients, a meal type and a preparation time.
43 | \end{enumerate}
44 | \subsection*{Input example}
45 | \begin{42console}
46 | >>> Enter a name:
47 | chips
48 | >>> Enter ingredients:
49 | potatoes
50 | oil
51 | salt
52 |
53 | >>> Enter a meal type:
54 | lunch
55 | >>> Enter a preparation time:
56 | 15
57 | \end{42console}
58 |
59 | % ================================= %
60 | \section*{Part 3: A command line executable !}
61 |
62 | Create a program that uses your \texttt{cookbook} and your functions.\\
63 | \newline
64 | The program will prompt the user to make a choice between printing the cookbook's content,
65 | printing one recipe, adding a recipe, deleting a recipe or quitting the cookbook.\\
66 | \newline
67 | Your program will continue to prompt the user until the user decides to quit it.\\
68 | \newline
69 | The program cannot crash if a wrong value is entered: you must handle the error and ask for another prompt.\\
70 |
71 | \begin{42console}
72 | $> python3 recipe.py
73 | Welcome to the Python Cookbook !
74 | List of available options:
75 | 1: Add a recipe
76 | 2: Delete a recipe
77 | 3: Print a recipe
78 | 4: Print the cookbook
79 | 5: Quit
80 |
81 | Please select an option:
82 | >> 3
83 |
84 | Please enter a recipe name to get its details:
85 | >> cake
86 |
87 | Recipe for cake:
88 | Ingredients list: ['flour', 'sugar', 'eggs']
89 | To be eaten for dessert.
90 | Takes 60 minutes of cooking.
91 |
92 | Please select an option:
93 | >> Hello
94 |
95 | Sorry, this option does not exist.
96 | List of available options:
97 | 1: Add a recipe
98 | 2: Delete a recipe
99 | 3: Print a recipe
100 | 4: Print the cookbook
101 | 5: Quit
102 |
103 | Please select an option:
104 | >> 5
105 |
106 | Cookbook closed. Goodbye !
107 | $>
108 | \end{42console}
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex07.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 07}
2 | \extitle{Shorter, Faster ... Pythonic !}
3 | \turnindir{ex07}
4 | \exnumber{07}
5 | \exfiles{filterwords.py}
6 | \exforbidden{filter}
7 | \makeheaderfilesforbidden
8 | Make a program that takes a string S and an integer N as argument and prints the list of words in S that contains more than N non-punctuation characters.
9 |
10 | \begin{itemize}
11 | \item Words are separated from each other by space characters
12 | \item Punctuation symbols must be removed from the printed list: they are neither part of a word nor a separator
13 | \item The program must contain at least one \textbf{list comprehension} expression.
14 | \end{itemize}
15 | If the number of argument is different from 2, or if the type of any argument is invalid, the program prints an error message.
16 |
17 | \section*{Examples}
18 | \begin{42console}
19 | $> python3 filterwords.py 'Hello, my friend' 3
20 | ['Hello', 'friend']
21 | $> python3 filterwords.py 'Hello, my friend' 10
22 | []
23 | $> python3 filterwords.py 'A robot must protect its own existence as long as such protection does not conflict with the First or Second Law' 6
24 | ['protect', 'existence', 'protection', 'conflict']
25 | $> python3 filterwords.py Hello World
26 | ERROR
27 | $> python3 filterwords.py 3 'Hello, my friend'
28 | ERROR
29 | $> python3 filterwords.py
30 | ERROR
31 | \end{42console}
32 |
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex08.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 08}
2 | \extitle{S.O.S}
3 | \turnindir{ex08}
4 | \exnumber{08}
5 | \exfiles{sos.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 | Make a program that takes a string as argument and encodes it into Morse code.
9 | \begin{itemize}
10 | \item The program supports space and alphanumeric characters
11 | \item An alphanumeric character is represented by dots \texttt{.} and dashes \texttt{-}
12 | \item A space character is represented by a slash \texttt{/}
13 | \item Complete morse characters are separated by a single space\\
14 | \end{itemize}
15 | If more than one argument is provided, merge them into a single string with each argument separated by a single space character.\\
16 | \newline
17 | If no argument is provided, do nothing or print an usage.
18 |
19 | % ================================= %
20 | \section*{Examples}
21 | \begin{42console}
22 | $> python3 sos.py "SOS"
23 | ... --- ...
24 | $> python3 sos.py
25 | $> python3 sos.py "HELLO / WORLD"
26 | ERROR
27 |
28 | $> python3 sos.py "96 BOULEVARD" "Bessiere"
29 | ----. -.... / -... --- ..- .-.. . ...- .- .-. -.. / -... . ... ... .. . .-. .
30 | \end{42console}
31 |
32 | \hint{
33 | \url{https://morsecode.world/international/morse2.html}
34 | }
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex09.aux:
--------------------------------------------------------------------------------
1 | \relax
2 | \providecommand\zref@newlabel[2]{}
3 | \providecommand\hyper@newdestlabel[2]{}
4 | \@writefile{toc}{\contentsline {chapter}{\numberline {XI}Exercise 09}{20}{chapter.11}\protected@file@percent }
5 | \@writefile{lof}{\addvspace {10\p@ }}
6 | \@writefile{lot}{\addvspace {10\p@ }}
7 | \@setckpt{exercises/m00ex09}{
8 | \setcounter{page}{22}
9 | \setcounter{equation}{0}
10 | \setcounter{enumi}{4}
11 | \setcounter{enumii}{0}
12 | \setcounter{enumiii}{0}
13 | \setcounter{enumiv}{0}
14 | \setcounter{footnote}{0}
15 | \setcounter{mpfootnote}{0}
16 | \setcounter{part}{0}
17 | \setcounter{chapter}{11}
18 | \setcounter{section}{0}
19 | \setcounter{subsection}{0}
20 | \setcounter{subsubsection}{0}
21 | \setcounter{paragraph}{0}
22 | \setcounter{subparagraph}{0}
23 | \setcounter{figure}{0}
24 | \setcounter{table}{0}
25 | \setcounter{lstnumber}{10}
26 | \setcounter{section@level}{0}
27 | \setcounter{Item}{4}
28 | \setcounter{Hfootnote}{0}
29 | \setcounter{bookmark@seq@number}{11}
30 | \setcounter{float@type}{16}
31 | \setcounter{lofdepth}{1}
32 | \setcounter{lotdepth}{1}
33 | \setcounter{FancyVerbLine}{0}
34 | \setcounter{listing}{0}
35 | \setcounter{mdf@globalstyle@cnt}{0}
36 | \setcounter{mdfcountframes}{0}
37 | \setcounter{mdf@env@i}{0}
38 | \setcounter{mdf@env@ii}{0}
39 | \setcounter{mdf@zref@counter}{0}
40 | \setcounter{exerciceCounter}{12}
41 | \setcounter{itemizeCounter}{0}
42 | \setcounter{lstlisting}{0}
43 | }
44 |
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex09.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 09}
2 | \extitle{Secret number}
3 | \turnindir{ex09}
4 | \exnumber{09}
5 | \exfiles{guess.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 | You have to make a program that will be an interactive guessing game.\\
9 | \newline
10 | It will prompt the user to guess a number between $1$ and $99$. The program will tell the user if their
11 | input is too high or too low.
12 | \newline
13 | The game ends when the user finds out the secret number or types \texttt{exit}.\\
14 | \newline
15 | You will import the \texttt{random} module with the \texttt{randint} function to get a random number.
16 | You have to count the number of trials and print that number when the user wins.
17 |
18 | \section*{Examples}
19 | \begin{42console}
20 | $> python guess.py
21 | This is an interactive guessing game!
22 | You have to enter a number between 1 and 99 to find out the secret number.
23 | Type 'exit' to end the game.
24 | Good luck!
25 |
26 | What's your guess between 1 and 99?
27 | >> 54
28 | Too high!
29 | What's your guess between 1 and 99?
30 | >> 34
31 | Too low!
32 | What's your guess between 1 and 99?
33 | >> 45
34 | Too high!
35 | What's your guess between 1 and 99?
36 | >> A
37 | That's not a number.
38 | What's your guess between 1 and 99?
39 | >> 43
40 | Congratulations, you've got it!
41 | You won in 5 attempts!
42 | \end{42console}
43 | If the user discovers the secret number on the first try, tell them !\\
44 | \newline
45 | If the secret number is 42, make a reference to Douglas Adams.\\
46 | \newline
47 |
48 | \begin{42console}
49 | $> python guess.py
50 | This is an interactive guessing game!
51 | You have to enter a number between 1 and 99 to find out the secret number.
52 | Type 'exit' to end the game.
53 | Good luck!
54 |
55 | What's your guess between 1 and 99?
56 | >> 42
57 | The answer to the ultimate question of life, the universe and everything is 42.
58 | Congratulations! You got it on your first try!
59 | \end{42console}
60 |
61 | Other example:
62 |
63 | \begin{42console}
64 | $> python guess.py
65 | This is an interactive guessing game!
66 | You have to enter a number between 1 and 99 to find out the secret number.
67 | Type 'exit' to end the game.
68 | Good luck!
69 |
70 | What's your guess between 1 and 99?
71 | >> exit
72 | Goodbye!
73 | \end{42console}
74 |
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex10.aux:
--------------------------------------------------------------------------------
1 | \relax
2 | \providecommand\zref@newlabel[2]{}
3 | \providecommand\hyper@newdestlabel[2]{}
4 | \@writefile{toc}{\contentsline {chapter}{\numberline {XII}Exercise 10}{22}{chapter.12}\protected@file@percent }
5 | \@writefile{lof}{\addvspace {10\p@ }}
6 | \@writefile{lot}{\addvspace {10\p@ }}
7 | \@setckpt{exercises/m00ex10}{
8 | \setcounter{page}{24}
9 | \setcounter{equation}{0}
10 | \setcounter{enumi}{4}
11 | \setcounter{enumii}{0}
12 | \setcounter{enumiii}{0}
13 | \setcounter{enumiv}{0}
14 | \setcounter{footnote}{0}
15 | \setcounter{mpfootnote}{0}
16 | \setcounter{part}{0}
17 | \setcounter{chapter}{12}
18 | \setcounter{section}{0}
19 | \setcounter{subsection}{0}
20 | \setcounter{subsubsection}{0}
21 | \setcounter{paragraph}{0}
22 | \setcounter{subparagraph}{0}
23 | \setcounter{figure}{0}
24 | \setcounter{table}{0}
25 | \setcounter{lstnumber}{5}
26 | \setcounter{section@level}{0}
27 | \setcounter{Item}{4}
28 | \setcounter{Hfootnote}{0}
29 | \setcounter{bookmark@seq@number}{12}
30 | \setcounter{float@type}{16}
31 | \setcounter{lofdepth}{1}
32 | \setcounter{lotdepth}{1}
33 | \setcounter{FancyVerbLine}{0}
34 | \setcounter{listing}{0}
35 | \setcounter{mdf@globalstyle@cnt}{0}
36 | \setcounter{mdfcountframes}{0}
37 | \setcounter{mdf@env@i}{0}
38 | \setcounter{mdf@env@ii}{0}
39 | \setcounter{mdf@zref@counter}{0}
40 | \setcounter{exerciceCounter}{12}
41 | \setcounter{itemizeCounter}{0}
42 | \setcounter{lstlisting}{0}
43 | }
44 |
--------------------------------------------------------------------------------
/module00/subject/exercises/m00ex10.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 10}
2 | \extitle{Loading bar!}
3 | \turnindir{ex10}
4 | \exnumber{10}
5 | \exfiles{loading.py}
6 | \exforbidden{\texttt{tqdm} or any library for automatic loading bar}
7 | \makeheaderfilesforbidden
8 | You are about to discover the \texttt{yield} operator!\\
9 | \newline
10 | So let's create a function called \texttt{ft\_progress(lst)}.\\
11 | \newline
12 | The function will display the progress of a \texttt{for} loop.\\
13 | \info{We strongly advise you to take a look at the wonderful \textbf{tqdm} library, it will come in handy in many situations !}
14 | \section*{Examples}
15 | \begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON
16 | listy = range(1000)
17 | ret = 0
18 | for elem in ft_progress(listy):
19 | ret += (elem + 3) % 5
20 | sleep(0.01)
21 | print()
22 | print(ret)
23 | \end{42console}
24 |
25 | \begin{42console}
26 | $> python loading.py
27 | ETA: 8.67s [ 23%][=====> ] 233/1000 | elapsed time 2.33s
28 | ...
29 | 2000
30 | \end{42console}
31 | \newpage
32 | \begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON
33 | listy = range(3333)
34 | ret = 0
35 | for elem in ft_progress(listy):
36 | ret += elem
37 | sleep(0.005)
38 | print()
39 | print(ret)
40 | \end{42console}
41 |
42 | \begin{42console}
43 | $> python loading.py
44 | ETA: 14.67s [ 9%][=> ] 327/3333 | elapsed time 1.33s
45 | ...
46 | 5552778
47 | \end{42console}
48 |
49 |
50 |
--------------------------------------------------------------------------------
/module01/attachments/banking_test1.py:
--------------------------------------------------------------------------------
1 | from the_bank import Account, Bank
2 |
3 | if __name__ == "__main__":
4 | bank = Bank()
5 | bank.add(Account(
6 | 'Smith Jane',
7 | zip='911-745',
8 | value=1000.0,
9 | bref='1044618427ff2782f0bbece0abd05f31'
10 | ))
11 | bank.add(Account(
12 | 'William John',
13 | zip='100-064',
14 | value=6460.0,
15 | ref='58ba2b9954cd278eda8a84147ca73c87',
16 | info=None,
17 | other='This is the vice president of the corporation'
18 | ))
19 |
20 | if bank.transfer('William John', 'Smith Jane', 545.0) is False:
21 | print('Failed')
22 | else:
23 | print('Success')
24 |
--------------------------------------------------------------------------------
/module01/attachments/banking_test2.py:
--------------------------------------------------------------------------------
1 | from the_bank import Account, Bank
2 |
3 | if __name__ == "__main__":
4 | bank = Bank()
5 | bank.add(Account(
6 | 'Smith Jane',
7 | zip='911-745',
8 | value=1000.0,
9 | ref='1044618427ff2782f0bbece0abd05f31'
10 | ))
11 | bank.add(Account(
12 | 'William John',
13 | zip='100-064',
14 | value=6460.0,
15 | ref='58ba2b9954cd278eda8a84147ca73c87',
16 | info=None
17 | ))
18 |
19 | if bank.transfer('William John', 'Smith Jane', 1000.0) is False:
20 | print('Failed')
21 |
22 | bank.fix_account('William John')
23 | bank.fix_account('Smith Jane')
24 |
25 | if bank.transfer('William John', 'Smith Jane', 1000.0) is False:
26 | print('Failed')
27 | else:
28 | print('Success')
29 |
--------------------------------------------------------------------------------
/module01/attachments/banking_test3.py:
--------------------------------------------------------------------------------
1 | from the_bank import Account, Bank
2 |
3 | if __name__ == "__main__":
4 | bank = Bank()
5 | acc_valid_1 = Account('Sherlock Holmes',
6 | zip='NW1 6XE',
7 | addr='221B Baker street'
8 | value=1000.0)
9 | acc_valid_2 = Account('James Watson',
10 | zip='NW1 6XE',
11 | addr='221B Baker street',
12 | value=25000.0,
13 | info=None)
14 |
15 | acc_invalid_4 = Account("Douglass",
16 | zip='42',
17 | addr='boulevard bessieres',
18 | value=42)
19 | acc_invalid_1 = Account("Adam",
20 | value=42,
21 | zip='0',
22 | addr='Somewhere')
23 | acc_invalid_2 = Account("Bender Bending Rodríguez",
24 | zip='1',
25 | addr='Mexico',
26 | value=42)
27 | acc_invalid_3 = Account("Charlotte",
28 | zip='2',
29 | addr='Somewhere in the Milky Way',
30 | value=42)
31 | acc_invalid_5 = Account("Edouard",
32 | zip='3',
33 | addr='France',
34 | value=42)
35 |
36 | bank.add(acc_valid_1)
37 | bank.add()
38 |
39 | #if bank.transfer('William John', 'Smith Jane', 1000.0) is False:
40 | # print('Failed')
41 | # bank.fix_account('William John')
42 | # bank.fix_account('Smith Jane')
43 | ## ...
44 | #if bank.transfer('William John', 'Smith Jane', 1000.0) is False:
45 | # print('Failed')
46 | #else:
47 | # print('Success')
48 |
--------------------------------------------------------------------------------
/module01/exercises/m01ex00.tex:
--------------------------------------------------------------------------------
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:
--------------------------------------------------------------------------------
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}
--------------------------------------------------------------------------------
/module01/exercises/m01ex03.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 03}
2 | \extitle{Generator!}
3 | \turnindir{ex03}
4 | \exnumber{03}
5 | \exfiles{generator.py}
6 | \exauthorize{random.randint, random.choice}
7 | \exforbidden{random.shuffle, random.sample}
8 | \makeheaderfilesforbidden
9 |
10 |
11 | % ================================= %
12 | \section*{Objective}
13 | % --------------------------------- %
14 | The goal of this exercise is to discover the concept of generator object in Python.
15 |
16 | % ================================= %
17 | \section*{Instructions}
18 | % --------------------------------- %
19 | Code a function called \texttt{generator} that takes a text as input (only printable characters), uses the string
20 | parameter \texttt{sep} as a splitting parameter, and \texttt{yield}s the resulting substrings.
21 |
22 | The function can take an optional argument.
23 | The options are:
24 | \begin{itemize}
25 | \item \texttt{shuffle}: shuffles the list of words,
26 | \item \texttt{unique}: returns a list where each word appears only once,
27 | \item \texttt{ordered}: sorts the words alphabetically.
28 | \end{itemize}
29 |
30 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
31 | # function prototype
32 | def generator(text, sep=" ", option=None):
33 | '''
34 | Splits the text according to sep value and yields the substrings.
35 | '''
36 | \end{minted}
37 |
38 | You can only call one option at a time.
39 |
40 | % ================================= %
41 | \section*{Examples}
42 | % --------------------------------- %
43 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
44 | >> text = "Le Lorem Ipsum est simplement du faux texte."
45 | >> for word in generator(text, sep=" "):
46 | ... print(word)
47 | ...
48 | Le
49 | Lorem
50 | Ipsum
51 | est
52 | simplement
53 | du
54 | faux
55 | texte.
56 |
57 | >> for word in generator(text, sep=" ", option="shuffle"):
58 | ... print(word)
59 | ...
60 | simplement
61 | texte.
62 | est
63 | faux
64 | Le
65 | Lorem
66 | Ipsum
67 | du
68 |
69 | >> for word in generator(text, sep=" ", option="ordered"):
70 | ... print(word)
71 | ...
72 | Ipsum
73 | Le
74 | Lorem
75 | du
76 | est
77 | faux
78 | simplement
79 | texte.
80 | \end{minted}
81 |
82 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
83 | >> text = "Lorem Ipsum Lorem Ipsum"
84 | >> for word in generator(text, sep=" ", option="unique"):
85 | ... print(word)
86 | ...
87 | Lorem
88 | Ipsum
89 | \end{minted}
90 |
91 | 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.
92 |
93 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
94 | >> text = 1.0
95 | >> for word in generator(text, sep="."):
96 | ... print(word)
97 | ...
98 | ERROR
99 | \end{minted}
--------------------------------------------------------------------------------
/module01/exercises/m01ex04.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 04}
2 | \extitle{Working with lists}
3 | \turnindir{ex04}
4 | \exnumber{04}
5 | \exfiles{eval.py}
6 | \exauthorize{zip and enumerate}
7 | \exforbidden{while}
8 | \makeheaderfilesforbidden
9 |
10 |
11 | % ================================= %
12 | \section*{Objective}
13 | % --------------------------------- %
14 | The goal of this exercise is to discover 2 useful methods for lists, tuples,
15 | dictionnaries (iterable class objects more generally) named \texttt{zip}
16 | and \texttt{enumerate}.
17 |
18 | % ================================= %
19 | \section*{Instructions}
20 | % --------------------------------- %
21 | Code a class \texttt{Evaluator}, that has two static functions named \texttt{zip\_evaluate}
22 | and \texttt{enumerate\_evaluate}.
23 |
24 |
25 | The goal of these 2 functions is to compute the sum of the lengths of every
26 | \texttt{words} of a given list weighted by a list of coefficients \texttt{coefs} (yes, the 2 functions should do the same thing).
27 |
28 | The lists \texttt{coefs} and \texttt{words} have to be of the same length. If this is not the
29 | case, the function should return -1.
30 |
31 | You have to obtain the desired result using \texttt{zip} in the \texttt{zip\_evaluate} function,
32 | and with \texttt{enumerate} in the \texttt{enumerate\_evaluate} function.
33 |
34 | % ================================= %
35 | \section*{Examples}
36 | % --------------------------------- %
37 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
38 | >> from eval import Evaluator
39 | >>
40 | >> words = ["Le", "Lorem", "Ipsum", "est", "simple"]
41 | >> coefs = [1.0, 2.0, 1.0, 4.0, 0.5]
42 | >> Evaluator.zip_evaluate(coefs, words)
43 | 32.0
44 | >> words = ["Le", "Lorem", "Ipsum", "n'", "est", "pas", "simple"]
45 | >> coefs = [0.0, -1.0, 1.0, -12.0, 0.0, 42.42]
46 | >> Evaluator.enumerate_evaluate(coefs, words)
47 | -1
48 | \end{minted}
49 |
50 |
--------------------------------------------------------------------------------
/module01/exercises/m01ex05.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 05}
2 | \extitle{Bank Account}
3 | \turnindir{ex05}
4 | \exnumber{05}
5 | \exfiles{the\_bank.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 | % ================================= %
10 | \section*{Objective}
11 | % --------------------------------- %
12 | The goal of this exercise is to discover new built-in functions,
13 | deepen your class understanding, and to be aware of modifications on
14 | instanced objects.\\
15 | In this exercise, you will learn how to modify or add attributes to an object.
16 |
17 | % ================================= %
18 | \section*{Instructions}
19 | % --------------------------------- %
20 | It is all about security.
21 | Have a look at the class named \texttt{Account} in the code snippet below.
22 |
23 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
24 | # in the_bank.py
25 | class Account(object):
26 |
27 | ID_COUNT = 1
28 |
29 | def __init__(self, name, **kwargs):
30 | self.__dict__.update(kwargs)
31 |
32 | self.id = self.ID_COUNT
33 | Account.ID_COUNT += 1
34 | self.name = name
35 | if not hasattr(self, 'value'):
36 | self.value = 0
37 |
38 | if self.value < 0:
39 | raise AttributeError("Attribute value cannot be negative.")
40 | if not isinstance(self.name, str)
41 | raise AttributeError("Attribute name must be a str object.")
42 |
43 | def transfer(self, amount):
44 | self.value += amount
45 | \end{minted}
46 |
47 | Now, it is your turn to code a class named \texttt{Bank}!
48 | Its purpose will be to handle the security part of each transfer attempt.
49 |
50 | Security means checking if the \texttt{Account} is:
51 | \begin{itemize}
52 | \item the right object,
53 | \item not corrupted,
54 | \item and stores enough money to complete the transfer.
55 | \end{itemize}
56 |
57 | How do we define if a bank account is corrupted? A corrupted bank account has:
58 | \begin{itemize}
59 | \item an even number of attributes,
60 | \item an attribute starting with \texttt{b},
61 | \item no attribute starting with \texttt{zip} or \texttt{addr},
62 | \item no attribute \texttt{name}, \texttt{id} and \texttt{value},
63 | \item \texttt{name} not being a string,
64 | \item \texttt{id} not being an \texttt{int},
65 | \item \texttt{value} not being an \texttt{int} or a \texttt{float}.
66 | \end{itemize}
67 |
68 | For the rest of the attributes (\texttt{addr}, \texttt{zip}, etc ...
69 | there is no specific check expected.
70 | Meaning you are not expected to evaluate the validity of the account based on the type of the other attributes (the conditions listed above are sufficient).
71 |
72 | Moreover, verification has to be performed when account objects are added to to Bank instance
73 | (\texttt{bank.add(Account(...))}).
74 | The verification in \texttt{add} only checsk the type of the new\_account and if there
75 | is no account among the ones already in Bank instance with the same name.
76 |
77 | A transaction is invalid if \texttt{amount < 0} or if the amount is larger than
78 | the balance of the account.
79 | Prior to the transfer, the validity of the 2 accounts (\texttt{origin} and \texttt{dest}) are checked
80 | (according to the list of criteria above).
81 | A transfer between the same account (\texttt{bank.transfer('Wiliam John', 'William John')})
82 | is valid but there is no fund movement.
83 |
84 | \texttt{fix\_account} recovers a corrupted account if it parameter \texttt{name} correspond to the attribute
85 | name of one of the account in \texttt{accounts} (attribute of Bank). If name is not a string or does not corresponded
86 | to an account name, the method return \texttt{False}.
87 |
88 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
89 | # in the_bank.py
90 | class Bank(object):
91 | """The bank"""
92 | def __init__(self):
93 | self.accounts = []
94 |
95 | def add(self, new_account):
96 | """ Add new_account in the Bank
97 | @new_account: Account() new account to append
98 | @return True if success, False if an error occured
99 | """
100 | # test if new_account is an Account() instance and if
101 | # it can be appended to the attribute accounts
102 |
103 | # ... Your code ...
104 |
105 | self.accounts.append(new_account)
106 |
107 | def transfer(self, origin, dest, amount):
108 | """" Perform the fund transfer
109 | @origin: str(name) of the first account
110 | @dest: str(name) of the destination account
111 | @amount: float(amount) amount to transfer
112 | @return True if success, False if an error occured
113 | """
114 | # ... Your code ...
115 |
116 | def fix_account(self, name):
117 | """ fix account associated to name if corrupted
118 | @name: str(name) of the account
119 | @return True if success, False if an error occured
120 | """
121 | # ... Your code ...
122 | \end{minted}
123 |
124 | Check out the \texttt{dir} built-in function.
125 |
126 | \warn{YOU WILL HAVE TO MODIFY THE INSTANCES' ATTRIBUTES IN ORDER TO FIX THEM.}
127 |
128 | % ================================= %
129 | \section*{Examples}
130 | % --------------------------------- %
131 | The script \texttt{banking\_test1.py} is a test which must print \texttt{Failed}.
132 | The second script \texttt{banking\_test2.py} is a test which must print \texttt{Failed} and then \texttt{Success}.
133 |
134 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{bash}
135 | >> python banking_test1.py
136 | Failed
137 | # The transaction is not performed has the account of Smith Jane is corrupted (due to the attribute 'bref').
138 |
139 | >> python banking_test2.py
140 | Failed
141 | Success
142 | # the account are false due to the abscence of addr attribute, fix_account recover the account,
143 | # thus they become valid.
144 | \end{minted}
145 |
146 |
--------------------------------------------------------------------------------
/module01/exercises/m01ex06.tex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module01/exercises/m01ex06.tex
--------------------------------------------------------------------------------
/module01/exercises/m01ex07.tex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module01/exercises/m01ex07.tex
--------------------------------------------------------------------------------
/module01/exercises/m01ex08.tex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module01/exercises/m01ex08.tex
--------------------------------------------------------------------------------
/module01/subject/Makefile:
--------------------------------------------------------------------------------
1 | # List the pdf's to build. foo.tex will produce foo.pdf
2 | TARGETS = en.subject.pdf
3 |
4 | # List the files included in the slides
5 | DEPS =
6 |
7 | # Relative path to the LaTeX documentclass setup files
8 | # Adapt as needed
9 | # RELPATH = $(shell git rev-parse --show-toplevel)/resources/latex/
10 | # RELPATH for github actions:
11 | RELPATH = $(shell pwd)/../../resources/latex/
12 |
13 | # You should not touch this either
14 | include $(RELPATH)/Makefile.LaTeX
15 |
--------------------------------------------------------------------------------
/module01/subject/assets/42ai_logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module01/subject/assets/42ai_logo.pdf
--------------------------------------------------------------------------------
/module01/subject/en.acknowledgements.tex:
--------------------------------------------------------------------------------
1 | \section*{Contact}
2 | % --------------------------------- %
3 | You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\
4 | \newline
5 | Thank you for attending 42AI's Python Bootcamp module01 !
6 |
7 | % ================================= %
8 | \section*{Acknowledgements}
9 | % --------------------------------- %
10 | The Python bootcamp is the result of a collective work, for which we would like to thank:
11 | \begin{itemize}
12 | \item Maxime Choulika (cmaxime),
13 | \item Pierre Peigné (ppeigne, pierre@42ai.fr),
14 | \item Matthieu David (mdavid, matthieu@42ai.fr),
15 | \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr)
16 | \item Mathieu Perez (maperez, mathieu.perez@42ai.fr)
17 | \end{itemize}
18 | who supervised the creation, the enhancement of the bootcamp and this present transcription.
19 |
20 | \begin{itemize}
21 | \item Louis Develle (ldevelle, louis@42ai.fr)
22 | \item Augustin Lopez (aulopez)
23 | \item Luc Lenotre (llenotre)
24 | \item Owen Roberts (oroberts)
25 | \item Thomas Flahault (thflahau)
26 | \item Amric Trudel (amric@42ai.fr)
27 | \item Baptiste Lefeuvre (blefeuvr@student.42.fr)
28 | \item Mathilde Boivin (mboivin@student.42.fr)
29 | \item Tristan Duquesne (tduquesn@student.42.fr)
30 | \end{itemize}
31 | for your investment in the creation and development of these modules.
32 |
33 | \begin{itemize}
34 | \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps !
35 | \end{itemize}
36 |
37 | \vfill
38 | \doclicenseThis
--------------------------------------------------------------------------------
/module01/subject/en.instructions.tex:
--------------------------------------------------------------------------------
1 | \chapter{Common Instructions}
2 | \begin{itemize}
3 | \item The version of Python recommended to use is 3.7, you can
4 | check the version of Python with the following command: \texttt{python -V}
5 |
6 | \item The norm: during this bootcamp, it is recommended to follow the
7 | \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory.
8 | You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which
9 | is a tool to check your Python code.
10 | \item The function \texttt{eval} is never allowed.
11 | \item The exercises are ordered from the easiest to the hardest.
12 | \item Your exercises are going to be evaluated by someone else,
13 | so make sure that your variable names and function names are appropriate and civil.
14 | \item Your manual is the internet.
15 |
16 | \item If you are a student from 42, you can access our Discord server
17 | on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your
18 | questions to your peers in the dedicated Bootcamp channel.
19 |
20 | \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}.
21 |
22 | \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}.
23 |
24 | \item We encourage you to create test programs for your
25 | project even though this work \textbf{won't have to be
26 | submitted and won't be graded}. It will give you a chance
27 | to easily test your work and your peers’ work. You will find
28 | those tests especially useful during your defence. Indeed,
29 | during defence, you are free to use your tests and/or the
30 | tests of the peer you are evaluating.
31 |
32 | \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\
33 | You can tell us more about your experience with this module by filling \href{https://forms.gle/rYDeueNgBrXRfE7aA}{this form}.\\
34 | Thank you in advance and good luck for this bootcamp !
35 |
36 | \end{itemize}
--------------------------------------------------------------------------------
/module01/subject/en.subject.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module01/subject/en.subject.pdf
--------------------------------------------------------------------------------
/module01/subject/en.subject.tex:
--------------------------------------------------------------------------------
1 | % vim: set ts=4 sw=4 tw=80 noexpandtab:
2 |
3 | \documentclass{42-en}
4 | \usepackage{amsmath}
5 |
6 | %******************************************************************************%
7 | % %
8 | % Prologue %
9 | % %
10 | %******************************************************************************%
11 | \usepackage[
12 | type={CC},
13 | modifier={by-nc-sa},
14 | version={4.0},
15 | ]{doclicense}
16 |
17 | %****************************************************************%
18 | % Re/definition of commands %
19 | %****************************************************************%
20 |
21 | \newcommand{\ailogo}[1]{\def \@ailogo {#1}}\ailogo{assets/42ai_logo.pdf}
22 |
23 | %% Redefine \maketitle
24 | \makeatletter
25 | \def \maketitle {
26 | \begin{titlepage}
27 | \begin{center}
28 | %\begin{figure}[t]
29 | %\includegraphics[height=8cm]{\@ailogo}
30 | \includegraphics[height=8cm]{assets/42ai_logo.pdf}
31 | %\end{figure}
32 | \vskip 5em
33 | {\huge \@title}
34 | \vskip 2em
35 | {\LARGE \@subtitle}
36 | \vskip 4em
37 | \end{center}
38 | %\begin{center}
39 | %\@author
40 | %\end{center}
41 | %\vskip 5em
42 | \vfill
43 | \begin{center}
44 | \emph{\summarytitle : \@summary}
45 | \end{center}
46 | \vspace{2cm}
47 | %\vskip 5em
48 | %\doclicenseThis
49 | \end{titlepage}
50 | }
51 | \makeatother
52 |
53 | \makeatletter
54 | \def \makeheaderfilesforbidden
55 | {
56 | \noindent
57 | \begin{tabularx}{\textwidth}{|X X X X|}
58 | \hline
59 | \multicolumn{1}{|>{\raggedright}m{1cm}|}
60 | {\vskip 2mm \includegraphics[height=1cm]{assets/42ai_logo.pdf}} &
61 | \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } &
62 | \multicolumn{1}{ >{\raggedleft}p{1.5cm}|}
63 | %% {\scriptsize points : \@exscore} \\ \hline
64 | {} \\ \hline
65 |
66 | \multicolumn{4}{|>{\centering}m{15cm}|}
67 | {\small \@extitle} \\ \hline
68 |
69 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
70 | {\small Turn-in directory : \ttfamily
71 | $ex\@exnumber/$ }
72 | \\ \hline
73 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
74 | {\small Files to turn in : \ttfamily \@exfiles }
75 | \\ \hline
76 |
77 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
78 | {\small Forbidden functions : \ttfamily \@exforbidden }
79 | \\ \hline
80 |
81 | %% \multicolumn{4}{|>{\raggedright}m{15cm}|}
82 | %% {\small Remarks : \ttfamily \@exnotes }
83 | %% \\ \hline
84 | \end{tabularx}
85 | %% \exnotes
86 | \exrules
87 | \exmake
88 | \exauthorize{None}
89 | \exforbidden{None}
90 | \extitle{}
91 | \exnumber{}
92 | }
93 | \makeatother
94 |
95 | %% Syntactic highlights
96 | \makeatletter
97 | \newenvironment{pythoncode}{%
98 | \VerbatimEnvironment
99 | \usemintedstyle{emacs}
100 | \minted@resetoptions
101 | \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize}
102 | \begin{figure}[ht!]
103 | \centering
104 | \begin{minipage}{16cm}
105 | \begin{VerbatimOut}{\jobname.pyg}}
106 | {%[
107 | \end{VerbatimOut}
108 | \minted@pygmentize{c}
109 | \DeleteFile{\jobname.pyg}
110 | \end{minipage}
111 | \end{figure}}
112 | \makeatother
113 |
114 | \usemintedstyle{native}
115 |
116 | \begin{document}
117 |
118 | % =============================================================================%
119 | % ===================================== %
120 |
121 | \title{Python Bootcamp - Module 01}
122 | \subtitle{Basics 2}
123 | \author{}
124 | \summary
125 | {
126 | The goal of this module is to get familiar with the Object-Oriented Programming ('OOP')
127 | paradigm, and more ...
128 | }
129 |
130 | \maketitle
131 | \input{en.instructions.tex}
132 | \newpage
133 | \tableofcontents
134 | \startexercices
135 |
136 | % ===================================== %
137 | % =============================================================================%
138 | %******************************************************************************%
139 | % %
140 | % Exercises %
141 | % %
142 | %******************************************************************************%
143 | % ============================================== %
144 | % ===========================(start ex 00) %
145 | \input{exercises/m01ex00.tex}
146 | % ===========================(fin ex 00) %
147 | \newpage
148 | % ===========================(start ex 01) %
149 | \input{exercises/m01ex01.tex}
150 | % ===========================(fin ex 01) %
151 | \newpage
152 | % ===========================(start ex 02) %
153 | \input{exercises/m01ex02.tex}
154 | % ===========================(fin ex 02) %
155 | \newpage
156 | % ===========================(start ex 03) %
157 | \input{exercises/m01ex03.tex}
158 | % ===========================(fin ex 03) %
159 | \newpage
160 | % ===========================(start ex 04) %
161 | \input{exercises/m01ex04.tex}
162 | % ===========================(fin ex 04) %
163 | \newpage
164 | % ===========================(start ex 05) %
165 | \input{exercises/m01ex05.tex}
166 | % ===========================(fin ex 05) %
167 | \newpage
168 | \input{en.acknowledgements.tex}
169 |
170 | \end{document}
--------------------------------------------------------------------------------
/module02/attachments/good.csv:
--------------------------------------------------------------------------------
1 | "Name", "Sex", "Age", "Height (in)", "Weight (lbs)"
2 | "Alex", "M", 41, 74, 170
3 | "Bert", "M", 42, 68, 166
4 | "Carl", "M", 32, 70, 155
5 | "Dave", "M", 39, 72, 167
6 | "Elly", "F", 30, 66, 124
7 | "Fran", "F", 33, 66, 115
8 | "Gwen", "F", 26, 64, 121
9 | "Hank", "M", 30, 71, 158
10 | "Ivan", "M", 53, 72, 175
11 | "Jake", "M", 32, 69, 143
12 | "Kate", "F", 47, 69, 139
13 | "Luke", "M", 34, 72, 163
14 | "Myra", "F", 23, 62, 98
15 | "Neil", "M", 36, 75, 160
16 | "Omar", "M", 38, 70, 145
17 | "Page", "F", 31, 67, 135
18 | "Quin", "M", 29, 71, 176
19 | "Ruth", "F", 28, 65, 131
20 |
--------------------------------------------------------------------------------
/module02/subject/Makefile:
--------------------------------------------------------------------------------
1 | # List the pdf's to build. foo.tex will produce foo.pdf
2 | TARGETS = en.subject.pdf
3 |
4 | # List the files included in the slides
5 | DEPS =
6 |
7 | # Relative path to the LaTeX documentclass setup files
8 | # Adapt as needed
9 | # RELPATH = $(shell git rev-parse --show-toplevel)/resources/latex/
10 | # RELPATH for github actions:
11 | RELPATH = $(shell pwd)/../../resources/latex/
12 |
13 | # You should not touch this either
14 | include $(RELPATH)/Makefile.LaTeX
15 |
--------------------------------------------------------------------------------
/module02/subject/assets/42ai_logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module02/subject/assets/42ai_logo.pdf
--------------------------------------------------------------------------------
/module02/subject/en.acknowledgements.tex:
--------------------------------------------------------------------------------
1 | \section*{Contact}
2 | % --------------------------------- %
3 | You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\
4 | \newline
5 | Thank you for attending 42AI's Python Bootcamp module02 !
6 |
7 | % ================================= %
8 | \section*{Acknowledgements}
9 | % --------------------------------- %
10 | The Python bootcamp is the result of a collective work, for which we would like to thank:
11 | \begin{itemize}
12 | \item Maxime Choulika (cmaxime),
13 | \item Pierre Peigné (ppeigne, pierre@42ai.fr),
14 | \item Matthieu David (mdavid, matthieu@42ai.fr),
15 | \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr)
16 | \item Mathieu Perez (maperez, mathieu.perez@42ai.fr)
17 | \end{itemize}
18 | who supervised the creation, the enhancement of the bootcamp and this present transcription.
19 |
20 | \begin{itemize}
21 | \item Louis Develle (ldevelle, louis@42ai.fr)
22 | \item Augustin Lopez (aulopez)
23 | \item Luc Lenotre (llenotre)
24 | \item Owen Roberts (oroberts)
25 | \item Thomas Flahault (thflahau)
26 | \item Amric Trudel (amric@42ai.fr)
27 | \item Baptiste Lefeuvre (blefeuvr@student.42.fr)
28 | \item Mathilde Boivin (mboivin@student.42.fr)
29 | \item Tristan Duquesne (tduquesn@student.42.fr)
30 | \end{itemize}
31 | for your investment in the creation and development of these modules.
32 |
33 | \begin{itemize}
34 | \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps !
35 | \end{itemize}
36 |
37 | \vfill
38 | \doclicenseThis
--------------------------------------------------------------------------------
/module02/subject/en.instructions.tex:
--------------------------------------------------------------------------------
1 | \chapter{Common Instructions}
2 | \begin{itemize}
3 | \item The version of Python recommended to use is 3.7, you can
4 | check the version of Python with the following command: \texttt{python -V}
5 |
6 | \item The norm: during this bootcamp, it is recommended to follow the
7 | \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory.
8 | You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which
9 | is a tool to check your Python code.
10 | \item The function \texttt{eval} is never allowed.
11 | \item The exercises are ordered from the easiest to the hardest.
12 | \item Your exercises are going to be evaluated by someone else,
13 | so make sure that your variable names and function names are appropriate and civil.
14 | \item Your manual is the internet.
15 |
16 | \item If you are a student from 42, you can access our Discord server
17 | on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your
18 | questions to your peers in the dedicated Bootcamp channel.
19 |
20 | \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}.
21 |
22 | \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}.
23 |
24 | \item We encourage you to create test programs for your
25 | project even though this work \textbf{won't have to be
26 | submitted and won't be graded}. It will give you a chance
27 | to easily test your work and your peers’ work. You will find
28 | those tests especially useful during your defence. Indeed,
29 | during defence, you are free to use your tests and/or the
30 | tests of the peer you are evaluating.
31 |
32 | \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\
33 | You can tell us more about your experience with this module by filling \href{https://forms.gle/xbm2VjynZq8BfpbM6}{this form}.\\
34 | Thank you in advance and good luck for this bootcamp !
35 |
36 | \end{itemize}
--------------------------------------------------------------------------------
/module02/subject/en.subject.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module02/subject/en.subject.pdf
--------------------------------------------------------------------------------
/module02/subject/en.subject.tex:
--------------------------------------------------------------------------------
1 | % vim: set ts=4 sw=4 tw=80 noexpandtab:
2 |
3 | \documentclass{42-en}
4 |
5 | %******************************************************************************%
6 | % %
7 | % Prologue %
8 | % %
9 | %******************************************************************************%
10 | \usepackage{amsmath}
11 | \usepackage[
12 | type={CC},
13 | modifier={by-nc-sa},
14 | version={4.0},
15 | ]{doclicense}
16 |
17 | %****************************************************************%
18 | % Re/definition of commands %
19 | %****************************************************************%
20 |
21 | \newcommand{\ailogo}[1]{\def \@ailogo {#1}}\ailogo{assets/42ai_logo.pdf}
22 |
23 | %% Redefine \maketitle
24 | \makeatletter
25 | \def \maketitle {
26 | \begin{titlepage}
27 | \begin{center}
28 | %\begin{figure}[t]
29 | %\includegraphics[height=8cm]{\@ailogo}
30 | \includegraphics[height=8cm]{assets/42ai_logo.pdf}
31 | %\end{figure}
32 | \vskip 5em
33 | {\huge \@title}
34 | \vskip 2em
35 | {\LARGE \@subtitle}
36 | \vskip 4em
37 | \end{center}
38 | %\begin{center}
39 | %\@author
40 | %\end{center}
41 | %\vskip 5em
42 | \vfill
43 | \begin{center}
44 | \emph{\summarytitle : \@summary}
45 | \end{center}
46 | \vspace{2cm}
47 | %\vskip 5em
48 | %\doclicenseThis
49 | \end{titlepage}
50 | }
51 | \makeatother
52 |
53 | \makeatletter
54 | \def \makeheaderfilesforbidden
55 | {
56 | \noindent
57 | \begin{tabularx}{\textwidth}{|X X X X|}
58 | \hline
59 | \multicolumn{1}{|>{\raggedright}m{1cm}|}
60 | {\vskip 2mm \includegraphics[height=1cm]{assets/42ai_logo.pdf}} &
61 | \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } &
62 | \multicolumn{1}{ >{\raggedleft}p{1.5cm}|}
63 | %% {\scriptsize points : \@exscore} \\ \hline
64 | {} \\ \hline
65 |
66 | \multicolumn{4}{|>{\centering}m{15cm}|}
67 | {\small \@extitle} \\ \hline
68 |
69 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
70 | {\small Turn-in directory : \ttfamily
71 | $ex\@exnumber/$ }
72 | \\ \hline
73 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
74 | {\small Files to turn in : \ttfamily \@exfiles }
75 | \\ \hline
76 |
77 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
78 | {\small Forbidden functions : \ttfamily \@exforbidden }
79 | \\ \hline
80 |
81 | %% \multicolumn{4}{|>{\raggedright}m{15cm}|}
82 | %% {\small Remarks : \ttfamily \@exnotes }
83 | %% \\ \hline
84 | \end{tabularx}
85 | %% \exnotes
86 | \exrules
87 | \exmake
88 | \exauthorize{None}
89 | \exforbidden{None}
90 | \extitle{}
91 | \exnumber{}
92 | }
93 | \makeatother
94 |
95 | %% Syntactic highlights
96 | \makeatletter
97 | \newenvironment{pythoncode}{%
98 | \VerbatimEnvironment
99 | \usemintedstyle{emacs}
100 | \minted@resetoptions
101 | \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize}
102 | \begin{figure}[ht!]
103 | \centering
104 | \begin{minipage}{16cm}
105 | \begin{VerbatimOut}{\jobname.pyg}}
106 | {%[
107 | \end{VerbatimOut}
108 | \minted@pygmentize{c}
109 | \DeleteFile{\jobname.pyg}
110 | \end{minipage}
111 | \end{figure}}
112 | \makeatother
113 |
114 | \usemintedstyle{native}
115 |
116 | \begin{document}
117 |
118 | % =============================================================================%
119 | % ===================================== %
120 |
121 | \title{Python Bootcamp - Module 02}
122 | \subtitle{Basics 3}
123 | \author{
124 | Maxime Choulika (cmaxime), Pierre Peigné (ppeigne), Matthieu David (mdavid)
125 | }
126 |
127 | \summary
128 | {
129 | Let's continue practicing with more advanced Python programming exercises.
130 | Destination: Decorators, lambda, context manager and packaging.
131 | }
132 |
133 | \maketitle
134 | \input{en.instructions.tex}
135 | \newpage
136 | \tableofcontents
137 | \startexercices
138 |
139 | % ===================================== %
140 | % =============================================================================%
141 |
142 |
143 | %******************************************************************************%
144 | % %
145 | % Exercises %
146 | % %
147 | %******************************************************************************%
148 |
149 | % ============================================== %
150 | % ===========================(start ex 00) %
151 | \input{exercises/m02ex00.tex}
152 | % ===========================(fin ex 00) %
153 | % ============================================== %
154 | \newpage
155 | % ============================================== %
156 | % ===========================(start ex 01) %
157 | \input{exercises/m02ex01.tex}
158 | % ===========================(fin ex 01) %
159 | % ============================================== %
160 | \newpage
161 | % ============================================== %
162 | % ===========================(start ex 02) %
163 | \input{exercises/m02ex02.tex}
164 | % ===========================(fin ex 02) %
165 | % ============================================== %
166 | \newpage
167 | % ============================================== %
168 | % ===========================(start ex 03) %
169 | \input{exercises/m02ex03.tex}
170 | % ===========================(fin ex 03) %
171 | % ============================================== %
172 | \newpage
173 | % ============================================== %
174 | % ===========================(start ex 04) %
175 | \input{exercises/m02ex04.tex}
176 | % ===========================(fin ex 04) %
177 | % ============================================== %
178 | \newpage
179 | % ============================================== %
180 | % ===========================(start ex 05) %
181 | \input{exercises/m02ex05.tex}
182 | % ===========================(fin ex 05) %
183 | % ============================================== %
184 | \newpage
185 | % ================================= %
186 | \input{en.acknowledgements.tex}
187 | % ================================= %
188 | \end{document}
189 |
--------------------------------------------------------------------------------
/module02/subject/exercises/m02ex00.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 00}
2 | \extitle{Map, filter, reduce}
3 | \turnindir{ex00}
4 | \exnumber{00}
5 | \exfiles{ft\_map.py, ft\_filter.py, ft\_reduce.py}
6 | \exforbidden{map, filter, reduce}
7 | \makeheaderfilesforbidden
8 |
9 | % ================================== %
10 | \section*{Objective}
11 | % ---------------------------------- %
12 | The goal of this exercise is to work on the built-in functions \texttt{map},
13 | \texttt{filter} and \texttt{reduce}.
14 |
15 | % ================================== %
16 | \section*{Instructions}
17 | % ---------------------------------- %
18 | Implement the functions \texttt{ft\_map}, \texttt{ft\_filter} and \texttt{ft\_reduce}.\\
19 | \\
20 | Take the time to understand the use cases of these two built-in functions
21 | (\texttt{map} and \texttt{filter}) and the function \texttt{reduce} in the functools module.\\
22 | \\
23 | You are not expected to code specific classes to create \texttt{ft\_map},
24 | \texttt{ft\_filter} or \texttt{ft\_reduce} objects, take a closer look
25 | at the examples to know what to do.\\
26 | \\
27 | Here are the signatures of the functions:\
28 | \\
29 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
30 | def ft_map(function_to_apply, iterable):
31 | """Map the function to all elements of the iterable.
32 | Args:
33 | function_to_apply: a function taking an iterable.
34 | iterable: an iterable object (list, tuple, iterator).
35 | Return:
36 | An iterable.
37 | None if the iterable can not be used by the function.
38 | """
39 | # ... Your code here ...
40 |
41 | def ft_filter(function_to_apply, iterable):
42 | """Filter the result of function apply to all elements of the iterable.
43 | Args:
44 | function_to_apply: a function taking an iterable.
45 | iterable: an iterable object (list, tuple, iterator).
46 | Return:
47 | An iterable.
48 | None if the iterable can not be used by the function.
49 | """
50 | # ... Your code here ...
51 |
52 | def ft_reduce(function_to_apply, iterable):
53 | """Apply function of two arguments cumulatively.
54 | Args:
55 | function_to_apply: a function taking an iterable.
56 | iterable: an iterable object (list, tuple, iterator).
57 | Return:
58 | A value, of same type of elements in the iterable parameter.
59 | None if the iterable can not be used by the function.
60 | """
61 | # ... Your code here ...
62 | \end{minted}
63 |
64 | % ================================== %
65 | \section*{Examples}
66 | % ---------------------------------- %
67 |
68 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
69 | # Example 1:
70 | x = [1, 2, 3, 4, 5]
71 | ft_map(lambda dum: dum + 1, x)
72 | # Output:
73 | # The adress will be different
74 |
75 | list(ft_map(lambda t: t + 1, x))
76 | # Output:
77 | [2, 3, 4, 5, 6]
78 |
79 | # Example 2:
80 | ft_filter(lambda dum: not (dum % 2), x)
81 | # Output:
82 | # The adress will be different
83 |
84 | list(ft_filter(lambda dum: not (dum % 2), x))
85 | # Output:
86 | [2, 4]
87 |
88 | # Example 3:
89 | lst = ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
90 | ft_reduce(lambda u, v: u + v, lst)
91 | # Output:
92 | "Hello world"
93 | \end{minted}
94 | \\
95 | You are expected to raise similar exceptions than those of
96 | \texttt{map}, \texttt{filter} and \texttt{reduce} when wrong parameters are given (but no need
97 | to reproduce the exact same exception messages).
--------------------------------------------------------------------------------
/module02/subject/exercises/m02ex01.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 01}
2 | \extitle{args and kwargs?}
3 | \turnindir{ex01}
4 | \exnumber{01}
5 | \exfiles{main.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 | % ================================= %
10 | \section*{Objective}
11 | % --------------------------------- %
12 | The goal of this exercise is to discover and manipulate \texttt{*args} and \texttt{**kwargs} arguments.
13 |
14 | % ================================= %
15 | \section*{Instructions}
16 | % --------------------------------- %
17 | In this exercise you have to implement a function named \texttt{what\_are\_the\_vars}
18 | which returns an instance of class ObjectC.\\
19 | \\
20 | ObjectC attributes are set via the parameters received during the instanciation.
21 | You will have to modify the 'instance' \texttt{ObjectC}, \textbf{NOT} the class.\\
22 | \\
23 | You should take a look at \texttt{getattr}, \texttt{setattr} built-in functions.\\
24 | \\
25 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
26 | def what_are_the_vars(...):
27 | """
28 | ...
29 | """
30 | # ... Your code here ...
31 |
32 | class ObjectC(object):
33 | def __init__(self):
34 | # ... Your code here ...
35 |
36 | def doom_printer(obj):
37 | if obj is None:
38 | print("ERROR")
39 | print("end")
40 | return
41 | for attr in dir(obj):
42 | if attr[0] != '_':
43 | value = getattr(obj, attr)
44 | print("{}: {}".format(attr, value))
45 | print("end")
46 |
47 | if __name__ == "__main__":
48 | obj = what_are_the_vars(7)
49 | doom_printer(obj)
50 | obj = what_are_the_vars(None, [])
51 | doom_printer(obj)
52 | obj = what_are_the_vars("ft_lol", "Hi")
53 | doom_printer(obj)
54 | obj = what_are_the_vars()
55 | doom_printer(obj)
56 | obj = what_are_the_vars(12, "Yes", [0, 0, 0], a=10, hello="world")
57 | doom_printer(obj)
58 | obj = what_are_the_vars(42, a=10, var_0="world")
59 | doom_printer(obj)
60 | obj = what_are_the_vars(42, "Yes", a=10, var_2="world")
61 | doom_printer(obj)
62 | \end{minted}
63 |
64 | % ================================= %
65 | \section*{Examples}
66 | % --------------------------------- %
67 |
68 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
69 | $> python main.py
70 | var_0: 7
71 | end
72 | var_0: None
73 | var_1: []
74 | end
75 | var_0: ft_lol
76 | var_1: Hi
77 | end
78 | end
79 | a: 10
80 | hello: world
81 | var_0: 12
82 | var_1: Yes
83 | var_2: [0, 0, 0]
84 | end
85 | ERROR
86 | end
87 | a: 10
88 | var_0: 42
89 | var_1: Yes
90 | var_2: world
91 | end
92 | \end{minted}
93 |
--------------------------------------------------------------------------------
/module02/subject/exercises/m02ex02.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 02}
2 | \extitle{The logger}
3 | \turnindir{ex02}
4 | \exnumber{02}
5 | \exfiles{logger.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 | % ================================= %
10 | \section*{Objective}
11 | % --------------------------------- %
12 | In this exercise, you will learn about decorators and we are not talking about
13 | the decoration of your room.\\
14 | \\
15 | The \texttt{@log} will write info about the decorated function in a
16 | \texttt{machine.log} file.\\
17 | \\
18 | % ================================= %
19 | \section*{Instructions}
20 | % --------------------------------- %
21 | You have to create the log decorator in the same file.\\
22 | \\
23 | Pay attention to all the different actions logged at the call of
24 | each method. You may notice the username from environment
25 | variables is written to the log file.\\
26 | \\
27 |
28 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
29 | import time
30 | from random import randint
31 | import os
32 |
33 | #... your definition of log decorator...
34 |
35 | class CoffeeMachine():
36 |
37 | water_level = 100
38 |
39 | @log
40 | def start_machine(self):
41 | if self.water_level > 20:
42 | return True
43 | else:
44 | print("Please add water!")
45 | return False
46 |
47 | @log
48 | def boil_water(self):
49 | return "boiling..."
50 |
51 | @log
52 | def make_coffee(self):
53 | if self.start_machine():
54 | for _ in range(20):
55 | time.sleep(0.1)
56 | self.water_level -= 1
57 | print(self.boil_water())
58 | print("Coffee is ready!")
59 |
60 | @log
61 | def add_water(self, water_level):
62 | time.sleep(randint(1, 5))
63 | self.water_level += water_level
64 | print("Blub blub blub...")
65 |
66 |
67 | if __name__ == "__main__":
68 |
69 | machine = CoffeeMachine()
70 | for i in range(0, 5):
71 | machine.make_coffee()
72 |
73 | machine.make_coffee()
74 | machine.add_water(70)
75 | \end{minted}
76 |
77 | % ================================= %
78 | \section*{Examples}
79 | % --------------------------------- %
80 | \begin{42console}
81 | $> python logger.py
82 | boiling...
83 | Coffee is ready!
84 | boiling...
85 | Coffee is ready!
86 | boiling...
87 | Coffee is ready!
88 | boiling...
89 | Coffee is ready!
90 | Please add water!
91 | Please add water!
92 | Blub blub blub...
93 | $>
94 | \end{42console}
95 |
96 | \begin{42console}
97 | $> cat machine.log
98 | (cmaxime)Running: Start Machine [ exec-time = 0.001 ms ]
99 | (cmaxime)Running: Boil Water [ exec-time = 0.005 ms ]
100 | (cmaxime)Running: Make Coffee [ exec-time = 2.499 s ]
101 | (cmaxime)Running: Start Machine [ exec-time = 0.002 ms ]
102 | (cmaxime)Running: Boil Water [ exec-time = 0.005 ms ]
103 | (cmaxime)Running: Make Coffee [ exec-time = 2.618 s ]
104 | (cmaxime)Running: Start Machine [ exec-time = 0.003 ms ]
105 | (cmaxime)Running: Boil Water [ exec-time = 0.004 ms ]
106 | (cmaxime)Running: Make Coffee [ exec-time = 2.676 s ]
107 | (cmaxime)Running: Start Machine [ exec-time = 0.003 ms ]
108 | (cmaxime)Running: Boil Water [ exec-time = 0.004 ms ]
109 | (cmaxime)Running: Make Coffee [ exec-time = 2.648 s ]
110 | (cmaxime)Running: Start Machine [ exec-time = 0.011 ms ]
111 | (cmaxime)Running: Make Coffee [ exec-time = 0.029 ms ]
112 | (cmaxime)Running: Start Machine [ exec-time = 0.009 ms ]
113 | (cmaxime)Running: Make Coffee [ exec-time = 0.024 ms ]
114 | (cmaxime)Running: Add Water [ exec-time = 5.026 s ]
115 | $>
116 | \end{42console}
117 | Pay attention, the length between ":" and "[" is 20].
118 | Draw the corresponding conclusions on this part of a log entry.
119 |
--------------------------------------------------------------------------------
/module02/subject/exercises/m02ex03.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 03}
2 | \extitle{Json issues}
3 | \turnindir{ex03}
4 | \exnumber{03}
5 | \exfiles{csvreader.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 | % ================================= %
10 | \section*{Objective}
11 | % --------------------------------- %
12 | The goal of this exercise is to implement a context manager as a class.\\
13 | Thus you are strongly encouraged to do some preliminary research about context manager.\\
14 |
15 | % ================================= %
16 | \section*{Instructions}
17 | % --------------------------------- %
18 | Implement a \texttt{CsvReader} class that opens, reads, and parses a CSV file.\\
19 | \
20 | This class is then a context manager as a class.\\
21 | \
22 | In order to create it, your class requires a few built-in methods:
23 | \begin{itemize}
24 | \item \texttt{\_\_init\_\_},
25 | \item \texttt{\_\_enter\_\_},
26 | \item \texttt{\_\_exit\_\_}.
27 | \end{itemize}
28 | It is mandatory to close the file once the process is completed.
29 | You are expected to handle properly badly-formatted CSV file (i.e. handle the exception):
30 |
31 | \begin{itemize}
32 | \item mistmatch between number of fields and number of records,
33 | \item records with different lengths.
34 | \end{itemize}
35 |
36 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
37 | class CsvReader():
38 | def __init__(self, filename=None, sep=',', header=False, skip_top=0, skip_bottom=0):
39 | # ... Your code here ...
40 |
41 | def __enter__(...):
42 | # ... Your code here ...
43 |
44 | def __exit__(...):
45 | # ... Your code here ...
46 |
47 | def getdata(self):
48 | """ Retrieves the data/records from skip_top to skip bottom.
49 | Returns:
50 | nested list (list(list, list, ...)) representing the data.
51 | """
52 | # ... Your code here ...
53 |
54 | def getheader(self):
55 | """ Retrieves the header from the csv file.
56 | Returns:
57 | list: representing the data (when self.header is True).
58 | None: (when self.header is False).
59 | """
60 | # ... Your code here ...
61 | \end{minted}
62 | \newline
63 | \texttt{CSV} (for Comma-Separated Values) files are delimited text files which use a given character to separate values.\\
64 | \\
65 | The separator (or delimiter) is usually a comma (\texttt{,}) or an hyphen comma (\texttt{;}),
66 | but with your context manager you have to offer the possibility to change this parameter.\\
67 | \\
68 | One can decide if the class instance skips lines at the top and the bottom of the file via the
69 | parameters \texttt{skip\_top} and \texttt{skip\_bottom}.\\
70 | \\
71 | One should also be able to keep the first line as a header if \texttt{header} is \texttt{True}.\\
72 | \\
73 | The file should not be corrupted (either a line with too many values or a line
74 | with too few values), otherwise return \texttt{None}.\\
75 | \\
76 | You have to handle the case \texttt{file not found}.\\
77 | \\
78 | You are expected to implement two methods:
79 | \begin{itemize}
80 | \item \texttt{getdata()},
81 | \item \texttt{getheader()}.
82 | \end{itemize}
83 |
84 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
85 | from csvreader import CsvReader
86 |
87 | if __name__ == "__main__":
88 | with CsvReader('good.csv') as file:
89 | data = file.getdata()
90 | header = file.getheader()
91 | \end{minted}
92 |
93 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
94 | from csvreader import CsvReader
95 |
96 | if __name__ == "__main__":
97 | with CsvReader('bad.csv') as file:
98 | if file == None:
99 | print("File is corrupted")
100 | \end{minted}
--------------------------------------------------------------------------------
/module02/subject/exercises/m02ex04.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 04}
2 | \extitle{MiniPack}
3 | \turnindir{ex04}
4 | \exnumber{04}
5 | \exfiles{build.sh, *.py, *.md, *.cfg, *.txt}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 |
10 | % ================================= %
11 | \section*{Objective}
12 | % --------------------------------- %
13 | The goal of this exercise is to learn how to build a package and understand the magnificence of \href{https://pypi.org/}{PyPi}.
14 |
15 | % ================================= %
16 | \section*{Instructions}
17 | % --------------------------------- %
18 | You have to create a package called \texttt{my\_minipack}.\\
19 | \hint{\href{https://docs.python.org/3.9/distributing/index.html}{RTFM}}
20 | It will have 2 \textbf{modules}:
21 | \begin{itemize}
22 | \item the progress bar (module00 ex10) which should be imported it via \texttt{import my\_minipack.progressbar},
23 | \item the logger (module02 ex02), which should be imported via \
24 | \texttt{import my\_minipack.logger}.
25 | \end{itemize}
26 | The package will be installed via pip using one of the following commands (both should work):
27 | \begin{42console}
28 | $> pip install ./dist/my_minipack-1.0.0.tar.gz
29 | $> pip install ./dist/my_minipack-1.0.0-py3-none-any.whl
30 | \end{42console}
31 | \
32 | Based on the following terminal commands and corresponding outputs, draw the necessary conclusion.
33 | \
34 | \begin{42console}
35 | $> python -m venv tmp_env && source tmp_env/bin/activate
36 | (tmp_env) > pip list
37 | # Ouput
38 | Package Version
39 | ---------- -------
40 | pip 19.0.3
41 | setuptools 40.8.0
42 |
43 | (tmp_env) $> cd ex04/ && bash build.sh
44 | # Output ... No specific verbose expected, do as you wish ...
45 | ...
46 | (tmp_env) $> ls dist
47 | # Output
48 | my_minipack-1.0.0-py3-none-any.whl my_minipack-1.0.0.tar.gz
49 |
50 | (tmp_env) $> pip list
51 | # Output
52 | Package Version
53 | ----------- -------
54 | my-minipack 1.0.0
55 | pip 21.0.1 # the last version at the time
56 | setuptools 54.2.0 # the last version at the time
57 | wheel 0.36.2 # the last version at the time
58 |
59 | (tmp_env) $> pip show -v my_minipack
60 | # Ouput (minimum metadata asked)
61 | Name: my-minipack
62 | Version: 1.0.0
63 | Summary: Howto create a package in python.
64 | Home-page: None
65 | Author: mdavid
66 | Author-email: mdavid@student.42.fr
67 | License: GPLv3
68 | Location: [PATH TO BOOTCAMP PYTHON]/module02/tmp_env/lib/python3.7/site-packages
69 | Requires:
70 | Required-by:
71 | Metadata-Version: 2.1
72 | Installer: pip
73 | Classifiers:
74 | Development Status :: 3 - Alpha
75 | Intended Audience :: Developers
76 | Intended Audience :: Students
77 | Topic :: Education
78 | Topic :: HowTo
79 | Topic :: Package
80 | License :: OSI Approved :: GNU General Public License v3 (GPLv3)
81 | Programming Language :: Python :: 3
82 | Programming Language :: Python :: 3 :: Only
83 | (tmp_env) $>
84 | \end{42console}
85 | Also add a LICENSE.md (you can choose a real license or a fake one it does not matter) and a README file where you will write a small documentation about your packaged library.
86 | \\
87 | The `build.sh` script upgrades `pip`, and \textbf{builds} the distribution packages in `wheel` and `egg` formats.
88 | \\
89 | \info{
90 | You can check whether the package was properly installed by running the command \texttt{pip list}
91 | that displays the list of installed packages and check the metadata of the package with
92 | \texttt{pip show -v my\_minipack}.
93 | Of course do not reproduce the exact same metadata, change the author information, modify the summary Topic and Audience items if you want to.
94 | }
--------------------------------------------------------------------------------
/module02/subject/exercises/m02ex05.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 05}
2 | \extitle{TinyStatistician}
3 | \turnindir{ex05}
4 | \exnumber{05}
5 | \exfiles{TinyStatistician.py}
6 | \exforbidden{Any function that calculates mean, median, quartiles, variance or standar deviation for you.}
7 | \makeheaderfilesforbidden
8 |
9 |
10 | % ================================= %
11 | \section*{Objective}
12 | % --------------------------------- %
13 | Initiation to very basic statistic notions.
14 |
15 | % ================================= %
16 | \section*{Instructions}
17 | % --------------------------------- %
18 | Create a class named \texttt{TinyStatistician} that implements the following methods:
19 | \begin{itemize}
20 | \item \texttt{mean(x)}: computes the mean of a given non-empty list or array \texttt{x}, using a for-loop.
21 | The method returns the mean as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array.
22 | Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its mean is:
23 | $$
24 | \mu = \frac{\sum_{i = 1}^{m}{x_i}}{m}
25 | $$
26 | \item \texttt{median(x)}: computes the median of a given non-empty list or array \texttt{x}.
27 | The method returns the median as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array.
28 | \item \texttt{quartiles(x)}: computes the $1^{\text{st}}$ and $3^{\text{rd}}$ quartiles of a given non-empty array \texttt{x}.
29 | The method returns the quartile as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array.
30 | \item \texttt{var(x)}: computes the variance of a given non-empty list or array \texttt{x}, using a for-loop.
31 | The method returns the variance as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array.
32 | Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its variance is:
33 | $$
34 | \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}
35 | $$
36 | \item \texttt{std(x)} : computes the standard deviation of a given non-empty list or array \texttt{x}, using a for-loop.
37 | The method returns the standard deviation as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array.
38 | Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its standard deviation is:
39 | $$
40 | \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}}
41 | $$
42 | \end{itemize}
43 | All methods take a \texttt{list} or a \texttt{numpy.ndarray} as parameter.\\
44 | \\
45 | We are assuming that all inputs have a correct format, i.e. a list or array of numeric type or empty list or array.\\
46 | \\
47 | You don't have to protect your functions against input errors.
48 | \\
49 | % ================================= %
50 | \section*{Examples}
51 | % --------------------------------- %
52 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
53 | from TinyStatistician import TinyStatistician
54 | tstat = TinyStatistician()
55 | a = [1, 42, 300, 10, 59]
56 |
57 | tstat.mean(a)
58 | # Expected result: 82.4
59 |
60 | tstat.median(a)
61 | # Expected result: 42.0
62 |
63 | tstat.quartile(a)
64 | # Expected result: [10.0, 59.0]
65 |
66 | tstat.var(a)
67 | # Expected result: 12279.439999999999
68 |
69 | tstat.std(a)
70 | # Expected result: 110.81263465868862
71 | \end{minted}
--------------------------------------------------------------------------------
/module03/assets/42AIlogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/42AIlogo.png
--------------------------------------------------------------------------------
/module03/assets/elon_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_blue.png
--------------------------------------------------------------------------------
/module03/assets/elon_blue_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_blue_2.png
--------------------------------------------------------------------------------
/module03/assets/elon_canaGAN.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_canaGAN.png
--------------------------------------------------------------------------------
/module03/assets/elon_canaGAN_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_canaGAN_2.png
--------------------------------------------------------------------------------
/module03/assets/elon_canaGAN_test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_canaGAN_test.png
--------------------------------------------------------------------------------
/module03/assets/elon_celluloid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_celluloid.png
--------------------------------------------------------------------------------
/module03/assets/elon_celluloid2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_celluloid2.png
--------------------------------------------------------------------------------
/module03/assets/elon_celluloid_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_celluloid_2.png
--------------------------------------------------------------------------------
/module03/assets/elon_green.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_green.png
--------------------------------------------------------------------------------
/module03/assets/elon_green_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_green_2.png
--------------------------------------------------------------------------------
/module03/assets/elon_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_inverted.png
--------------------------------------------------------------------------------
/module03/assets/elon_inverted_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_inverted_2.png
--------------------------------------------------------------------------------
/module03/assets/elon_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_red.png
--------------------------------------------------------------------------------
/module03/assets/elon_red_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/assets/elon_red_2.png
--------------------------------------------------------------------------------
/module03/attachments/42AI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/attachments/42AI.png
--------------------------------------------------------------------------------
/module03/attachments/elon_canaGAN.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/attachments/elon_canaGAN.png
--------------------------------------------------------------------------------
/module03/attachments/solar_system_census.csv:
--------------------------------------------------------------------------------
1 | ,height,weight,bone_density
2 | 0,172.27415062038824,86.97034919681435,1.0180982523703253
3 | 1,198.97747923087556,104.85555332290112,0.6974143350842494
4 | 2,207.11968071892977,87.40104688830093,0.7233613813886408
5 | 3,184.64272104623697,63.142295184724034,0.5477387058600002
6 | 4,179.38481426024376,67.52325676297193,1.0760223737947392
7 | 5,201.67421668806716,84.55237278642963,0.8687335396813632
8 | 6,172.47154362524978,85.11106318664459,0.7856501698632344
9 | 7,188.97654259355124,62.204422347740845,1.0286702082089587
10 | 8,181.45156018348482,88.18505434893899,0.9605785536049263
11 | 9,191.86364883955704,94.50057924390845,0.7353395189826079
12 | 10,190.94627687289778,87.95977702894372,0.8699854296759421
13 | 11,194.90737019817524,94.50831884545494,0.6861887067725907
14 | 12,188.61838809051892,94.53060942041576,0.6787531761116367
15 | 13,178.55793538697407,74.8899645368707,1.011808293174675
16 | 14,197.26037936062718,80.26354020244086,0.7029931596192053
17 | 15,182.30324452158274,96.47254943642713,0.7800637676057776
18 | 16,192.98571312509907,81.86156211110318,0.7053910422857453
19 | 17,187.63022056655893,82.64567557648942,0.8156638372387511
20 | 18,158.01387945151848,101.95335151682357,0.8961935948633638
21 | 19,194.90156778135,89.41811779325047,1.0323270015672699
22 | 20,167.62270464863246,95.98281844156745,0.7324276861941079
23 | 21,196.65249563766127,99.42320515192745,0.5529751394994343
24 | 22,184.75772430858464,86.10127810880446,0.7883748713831666
25 | 23,197.93881444046252,62.958610384107466,0.5662302631497813
26 | 24,165.30761397411942,74.78477597818247,0.800814230635404
27 | 25,199.15593147351345,88.43735480473818,0.9015740536146536
28 | 26,169.76250241347205,76.32405585105278,0.6876226928521314
29 | 27,188.98255658344306,109.67710031340968,0.7081708346021987
30 | 28,182.165885896533,82.0429076069452,1.0855309841011072
31 | 29,198.13746860184958,63.10024077288974,0.6698168051887734
32 | 30,181.2006560598653,79.11502291590423,1.0478493450317177
33 | 31,183.17079322487726,90.43983224147301,0.8015823979132396
34 | 32,194.21442246453552,114.35116049172063,0.7539270537250036
35 | 33,202.70844867774107,108.76534947152916,0.8807726080923401
36 | 34,184.26318081221564,68.08483624606978,1.1106692879928761
37 | 35,177.45038259754992,81.10474176415636,0.8086094555937088
38 | 36,198.48304576748265,71.23735879412602,1.0530205706165403
39 | 37,189.79895919856335,84.45183190025374,0.7660771023087605
40 | 38,177.78066463354017,77.1072982778667,0.8722843674861551
41 | 39,178.3797175848497,80.57215818455568,0.886294962312757
42 | 40,185.62455711006749,84.35399382675878,1.021724277223024
43 | 41,180.78035788492346,80.26102640875126,1.3981643075978238
44 | 42,181.7584817877156,71.47985246073034,0.9042419077628703
45 | 43,185.83703353826496,86.74770817976336,0.6107083181106511
46 | 44,203.05927435724928,107.65038644334588,0.6824769761690237
47 | 45,189.46908385480077,92.79253535217674,0.8537164072898876
48 | 46,192.35655957613915,88.89335692981177,0.7461553538847242
49 | 47,208.47479246635157,72.30235023927226,0.593505123997012
50 | 48,172.42658708222535,79.62929158503874,1.0983188438245455
51 | 49,175.12480014501418,86.25393069448258,1.016133557284088
52 | 50,191.6064524136488,83.21399525987887,0.7843340309268777
53 | 51,180.51466254047028,64.47981820140942,0.8430606254540093
54 | 52,166.25251579871335,68.79744511241171,0.9492545433353251
55 | 53,196.83284187478142,77.30505798317262,1.0688009801583602
56 | 54,203.1527256739121,75.97844807406175,0.5563251511763875
57 | 55,208.51013217417997,84.51606448618513,0.8273258400433119
58 | 56,187.98328398232508,77.43385205501818,0.8567497748005205
59 | 57,189.76350826723623,76.18764101500986,0.9887555981665755
60 | 58,171.03600876530075,60.28968107589418,0.9947946926660293
61 | 59,185.51618897481075,82.77522273072391,0.8926812382400297
62 | 60,171.49400736572338,85.40335875579838,0.951534447696775
63 | 61,173.79267290903599,75.72415821514427,0.9711524703396633
64 | 62,182.54526988319512,115.81302192752396,0.9124305014729545
65 | 63,213.32453058301897,98.62137103038879,0.7201621485471409
66 | 64,195.56514005110236,91.93894944821423,1.1160019452079735
67 | 65,199.24986802539019,76.15332108940318,0.6349009836196853
68 | 66,176.59079864010184,85.56812987015043,0.837472933606775
69 | 67,175.22645923498504,104.65843551155324,0.8005626747669411
70 | 68,189.2187075360297,82.8357602018288,0.919584933606487
71 | 69,188.82276636182,85.54925186621986,0.9079111881435697
72 | 70,171.48119101327381,77.98425500892046,0.7774045052500775
73 | 71,191.53965377652497,87.56201019904657,0.8035346866638218
74 | 72,187.09924711854072,113.30764875466105,0.7460120117820651
75 | 73,188.5310122346491,84.06558722226262,0.7424932488391015
76 | 74,192.5310855358553,99.61484689682668,0.9329028094927161
77 | 75,181.38005787312164,81.79963179947018,1.0192263945470665
78 | 76,175.56546051376606,79.96396484420819,1.2148319625601542
79 | 77,186.09057588236885,76.45955055588699,0.9113555502658368
80 | 78,189.75170076509616,88.92667115304232,0.8156186947366818
81 | 79,166.35036056308175,76.09202056154118,0.8692495719952581
82 | 80,196.0066411365781,94.19544918527832,0.902408033473065
83 | 81,184.26852751688608,92.22228974625632,0.8938794535190677
84 | 82,194.29676696491933,102.34260935489044,0.8853846293637079
85 | 83,191.34730698953368,85.24328827090298,0.6247578740519543
86 | 84,195.071758689715,86.60641988177326,0.7809722617537354
87 | 85,190.71263206580835,83.09721002418274,0.7859467572482429
88 | 86,191.74384646608553,70.90934077533176,0.7407037237463906
89 | 87,191.62954204965448,83.45709372544559,1.0834562921807067
90 | 88,189.02549526842665,71.01484511213982,0.4903471422258182
91 | 89,161.80417596756644,77.98511604657887,1.1817602705612857
92 | 90,209.42978769784648,79.33639650056047,0.772132592748897
93 | 91,165.68445274185433,81.74617948152768,0.9044109538306133
94 | 92,193.91865934637673,67.55816712080713,0.49401050860028506
95 | 93,192.74850292768483,67.874722746403,0.9146529386912636
96 | 94,152.4492189250862,77.10697430772929,1.0144324660744914
97 | 95,175.422805047458,90.93657381871118,0.5161676278343686
98 | 96,174.91116099060702,68.55143353804469,0.9618099655245396
99 | 97,182.88606365185723,81.75940685081667,0.871834350388935
100 | 98,172.62844557451567,74.90884189699447,0.693173089103024
101 | 99,208.5318924026477,64.45505703467397,0.8589210855025669
102 | 100,185.91110280231436,84.34224031420774,0.8944689419337465
103 | 101,171.83514170890868,73.32522883455526,0.9194802431608267
104 | 102,181.79885786205844,83.39515585034397,0.762877036737409
105 | 103,201.2227664085943,86.25475727295625,0.4432123559379535
106 | 104,193.19769078760004,106.73873767225655,0.8415185690682286
107 | 105,194.7430336094582,77.02695232887005,1.0241141713643551
108 | 106,179.58177529006747,78.27149794362192,1.0498386711328993
109 | 107,180.75377372111063,71.41114888311581,1.0807768171394512
110 | 108,161.43126852545078,72.06769928059661,1.1140469438717766
111 | 109,175.86969057824192,80.4150218352119,0.7831580768145175
112 | 110,187.3523853292341,72.93278418403746,0.8582529208618634
113 | 111,158.10327682856064,82.8634995273519,1.0858365848406863
114 | 112,162.59044319505395,83.30428904195806,1.1209007160852749
115 | 113,201.20937126779714,84.06252945567081,0.7100398299951398
116 | 114,177.1817618631796,61.16042167584998,0.8636374344328207
117 | 115,178.23041950866448,83.84590939652522,0.8986761907186256
118 | 116,194.02896849322792,85.55952141580629,0.7163308019605957
119 | 117,182.3085360691202,82.59055182454591,0.9946564902510409
120 | 118,193.9754126143204,95.81449234679603,0.7186661560362706
121 | 119,186.1094652387009,93.98876399412653,0.5233713264811798
122 |
--------------------------------------------------------------------------------
/module03/exercises/m03ex00.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 00}
2 | \extitle{NumPyCreator}
3 | \turnindir{ex00}
4 | \exnumber{00}
5 | \exfiles{NumPyCreator.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 | % ================================== %
10 | \section*{Objective}
11 | % ---------------------------------- %
12 | Introduction to the Numpy library.
13 |
14 | % ================================== %
15 | \section*{Instructions}
16 | % ---------------------------------- %
17 | Write a class named \texttt{NumPyCreator}, that implements all of the following methods.\\
18 | \\
19 | Each method receives as an argument a different type of data structure and transforms it into a Numpy array:
20 | \begin{itemize}
21 | \item \texttt{from\_list(self, lst)}: takes a list or nested lists and returns its corresponding Numpy array.
22 | \item \texttt{from\_tuple(self, tpl)}: takes a tuple or nested tuples and returns its corresponding Numpy array.
23 | \item \texttt{from\_iterable(self, itr)}: takes an iterable and returns an array which contains all of its elements.
24 | \item \texttt{from\_shape(self, shape, value)}: returns an array filled with the same value.
25 | The first argument is a tuple which specifies the shape of the array, and the second argument specifies the value of the elements.
26 | This value must be 0 by default.
27 | \item \texttt{random(self, shape)}: returns an array filled with random values.
28 | It takes as an argument a tuple which specifies the shape of the array.
29 | \item \texttt{identity(self, n)}: returns an array representing the identity matrix of size n.
30 | \end{itemize}
31 | \textit{\textbf{BONUS:}} Add to these methods an optional argument which specifies the datatype (dtype) of the array (e.g. to represent its elements as integers, floats, ...)
32 |
33 | \hint{Each of these methods can be implemented in one line. You only need to find the right Numpy functions.}
34 |
35 | % ================================== %
36 | \section*{Examples}
37 | % ---------------------------------- %
38 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
39 | from NumpyCreator import NumpyCreator
40 | npc = NumpyCreator()
41 |
42 | npc.from_list([[1,2,3],[6,3,4]])
43 | # Output :
44 | array([[1, 2, 3],
45 | [6, 3, 4]])
46 |
47 |
48 | npc.from_list([[1,2,3],[6,4]])
49 | # Output :
50 | None
51 |
52 |
53 | npc.from_list([[1,2,3],['a','b','c'],[6,4,7]])
54 | # Output :
55 | array([['1','2','3'],
56 | ['a','b','c'],
57 | ['6','4','7'], dtype='}, \texttt{\&} (or \texttt{and}).
159 | \end{itemize}
160 | \item \texttt{to\_grayscale}:
161 | \begin{itemize}
162 | \item Authorized functions: \texttt{.sum},\texttt{.shape},\texttt{.reshape},\texttt{.broadcast\_to},\texttt{.as\_type}.
163 | \item Authorized operators: \texttt{*},\texttt{/}, \texttt{=}.
164 | \end{itemize}
165 | \end{itemize}
166 | % ================================= %
167 | \section*{Examples}
168 | % --------------------------------- %
169 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
170 | from ImageProcessor import ImageProcessor
171 | imp = ImageProcessor()
172 | arr = imp.load("assets/42AI.png")
173 | # Output :
174 | Loading image of dimensions 200 x 200
175 |
176 |
177 | from ColorFilter import ColorFilter
178 | cf = ColorFilter()
179 | cf.invert(arr)
180 |
181 | cf.to_green(arr)
182 |
183 | cf.to_red(arr)
184 |
185 | cf.to_blue(arr)
186 |
187 | cf.to_celluloid(arr)
188 |
189 | cf.to_grayscale(arr, 'm')
190 |
191 | cf.to_grayscale(arr, 'weight', r_weight=0.2, 'g_weight'=0.3, 'b_weight'=0.5)
192 | \end{minted}
193 |
194 | \begin{figure}[h!]
195 | \begin{minipage}[l]{0.49\linewidth}
196 | \includegraphics[scale=0.38]{assets/elon_canaGAN.png}
197 | \vspace{-50pt}
198 | \caption{Elon Musk}
199 | \end{minipage}
200 | \hfill
201 | \begin{minipage}[c]{0.49\linewidth}
202 | \includegraphics[scale=0.38]{assets/elon_inverted.png}
203 | \vspace{-50pt}
204 | \caption{Inverted filter}
205 | \end{minipage}
206 | \vspace{-20pt}
207 | \begin{minipage}[l]{0.49\linewidth}
208 | \includegraphics[scale=0.38]{assets/elon_blue.png}
209 | \vspace{-50pt}
210 | \caption{Blue filter}
211 | \end{minipage}
212 | \hfill
213 | \begin{minipage}[c]{0.49\linewidth}
214 | \includegraphics[scale=0.38]{assets/elon_green.png}
215 | \vspace{-50pt}
216 | \caption{Green filter}
217 | \end{minipage}
218 | \vspace{-20pt}
219 | \begin{minipage}[l]{0.49\linewidth}
220 | \includegraphics[scale=0.38]{assets/elon_red.png}
221 | \vspace{-50pt}
222 | \caption{Red filter}
223 | \end{minipage}
224 | \hfill
225 | \begin{minipage}[c]{0.49\linewidth}
226 | \includegraphics[scale=0.38]{assets/elon_celluloid.png}
227 | \vspace{-50pt}
228 | \caption{Celluloid filter}
229 | \end{minipage}
230 |
231 | \end{figure}
232 |
233 | \info{
234 | The first image is a stylization of Elon Musk that has been generated using a style transfer algorithm implemented in our lab.
235 | You can see the code in 42AI repository \href{https://github.com/42-AI/StyleTransferMirror}{StyleTransferMirror}}
236 |
--------------------------------------------------------------------------------
/module03/exercises/m03ex04.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 04}
2 | \extitle{K-means Clustering}
3 | \turnindir{ex04}
4 | \exnumber{04}
5 | \exfiles{Kmeans.py}
6 | \exforbidden{Any functions allowing you to perform K-Means}
7 | \makeheaderfilesforbidden
8 |
9 | ALERT! DATA CORRUPTED
10 |
11 | % ================================= %
12 | \section*{Objective}
13 | % --------------------------------- %
14 | Implementation of a basic K-means algorithm.
15 |
16 | % ================================= %
17 | \section*{Instructions}
18 | % --------------------------------- %
19 | The solar system census dataset is corrupted! The citizens' homelands are missing!\\
20 | \\
21 | You must implement the K-means clustering algorithm in order to recover the citizens' origins.\\
22 | \\
23 | You can find good explanations on how K-means is working here:
24 | \href{https://en.wikipedia.org/wiki/K-means_clustering}{Wikipedia - K-Means clustering}\\
25 | \\
26 | The missing part is how to compute the distance between 2 data points (cluster centroid or a row in the data).\\
27 | \\
28 | In our case, the data we have to process is composed of 3 values (height, weight and bone\_density).\\
29 | \\
30 | Thus, each data point is a vector of 3 values.\\
31 | \\
32 | Now that we have mathematically defined our data points (vector of 3 values), it is very easy to compute the distance between two points using vector properties.\\
33 | You can use L1 distance, L2 distance, cosine similarity, and so forth...\\
34 | Choosing the distance to use is called hyperparameter tuning.\\
35 | \newline
36 | I would suggest you to try with the easiest setting (L1 distance) first.\\
37 | \\
38 | What you will notice is that the final result of the "training"/"fitting" will depend a lot on the random initialization.\\
39 | \\
40 | Commonly, in machine-learning libraries, K-means is run multiple times (with different random initializations) and the best result is saved.\\
41 | \\
42 | NB: To implement the fit function, keep in mind that a centroid can be considered as the gravity center of a set of points.\\
43 | \\
44 | Your program \texttt{Kmeans.py} takes 3 parameters: \texttt{filepath}, \texttt{max\_iter} and \texttt{ncentroid}:
45 |
46 | \begin{42console}
47 | python Kmeans.py filepath='../ressources/solar_system_census.csv' ncentroid=4 max_iter=30
48 | \end{42console}
49 |
50 | Your program is expected to:
51 | \begin{itemize}
52 | \item parse its arguments,
53 | \item read the dataset,
54 | \item fit the dataset,
55 | \item display the coordinates of the different centroids and the associated region (for the case \texttt{ncentroid=4}),
56 | \item display the number of individuals associated to each centroid,
57 | \item (Optional) display the results on 3 differents plots, corresponding to 3 combinations of 2 parameters, using different colors to distinguish between Venus,Earth, Mars and Belt asteroids citizens.
58 | \end{itemize}
59 |
60 | Create the class \texttt{KmeansClustering} with the following methods:
61 |
62 | \begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
63 | class KmeansClustering:
64 | def __init__(self, max_iter=20, ncentroid=5):
65 | self.ncentroid = ncentroid # number of centroids
66 | self.max_iter = max_iter # number of max iterations to update the centroids
67 | self.centroids = [] # values of the centroids
68 |
69 | def fit(self, X):
70 | """
71 | Run the K-means clustering algorithm.
72 | For the location of the initial centroids, randomly pick n centroids from the dataset.
73 | Args:
74 | -----
75 | X: has to be an numpy.ndarray, a matrice of dimension m * n.
76 | Return:
77 | -------
78 | None.
79 | Raises:
80 | -------
81 | This function should not raise any Exception.
82 | """
83 | ... your code ...
84 |
85 | def predict(self, X):
86 | """
87 | Predict from wich cluster each datapoint belongs to.
88 | Args:
89 | -----
90 | X: has to be an numpy.ndarray, a matrice of dimension m * n.
91 | Return:
92 | -------
93 | the prediction has a numpy.ndarray, a vector of dimension m * 1.
94 | Raises:
95 | -------
96 | This function should not raise any Exception.
97 | """
98 | ... your code ...
99 | \end{minted}
100 |
101 | % ================================= %
102 | \section*{Dataset}
103 | % --------------------------------- %
104 | The dataset, named \textbf{solar\_system\_census} can be found in
105 | the resources folder.\\
106 | \\
107 | It is a part of the solar system census dataset, and contains biometric
108 | data such as the height, weight, and bone density of solar
109 | system citizens.\\
110 | \\
111 | Solar citizens come from four registered areas:
112 | \begin{itemize}
113 | \item The flying cities of Venus,
114 | \item United Nations of Earth,
115 | \item Mars Republic,
116 | \item Asteroids' Belt colonies.
117 | \end{itemize}
118 | Unfortunately the data about the planets of origin was lost...\\
119 | Use your K-means algorithm to recover it!\\
120 | Once your clusters are found, try to find matches between clusters and the citizens' homelands.\\
121 |
122 | \hint{
123 | \begin{itemize}
124 | \item People are slender on Venus than on Earth.
125 | \item People of the Martian Republic are taller than on Earth.
126 | \item Citizens of the Belt are the tallest of the solar system and have the lowest bone density due to the lack of gravity.
127 | \end{itemize}
128 | }
129 |
130 | % ================================= %
131 | \section*{Examples}
132 | % --------------------------------- %
133 | Here is an example of the K-means algorithm in action:\\
134 | \url{https://i.ibb.co/bKFVVx2/ezgif-com-gif-maker.gif}
--------------------------------------------------------------------------------
/module03/subject/Makefile:
--------------------------------------------------------------------------------
1 | # List the pdf's to build. foo.tex will produce foo.pdf
2 | TARGETS = en.subject.pdf
3 |
4 | # List the files included in the slides
5 | DEPS =
6 |
7 | # Relative path to the LaTeX documentclass setup files
8 | # Adapt as needed
9 | # RELPATH = $(shell git rev-parse --show-toplevel)/resources/latex/
10 | # RELPATH for github actions:
11 | RELPATH = $(shell pwd)/../../resources/latex/
12 |
13 | # You should not touch this either
14 | include $(RELPATH)/Makefile.LaTeX
15 |
--------------------------------------------------------------------------------
/module03/subject/assets/42ai_logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/assets/42ai_logo.pdf
--------------------------------------------------------------------------------
/module03/subject/assets/capture_display_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/assets/capture_display_img.png
--------------------------------------------------------------------------------
/module03/subject/assets/elon_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/assets/elon_blue.png
--------------------------------------------------------------------------------
/module03/subject/assets/elon_canaGAN.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/assets/elon_canaGAN.png
--------------------------------------------------------------------------------
/module03/subject/assets/elon_celluloid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/assets/elon_celluloid.png
--------------------------------------------------------------------------------
/module03/subject/assets/elon_green.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/assets/elon_green.png
--------------------------------------------------------------------------------
/module03/subject/assets/elon_inverted.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/assets/elon_inverted.png
--------------------------------------------------------------------------------
/module03/subject/assets/elon_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/assets/elon_red.png
--------------------------------------------------------------------------------
/module03/subject/en.acknowledgements.tex:
--------------------------------------------------------------------------------
1 | \section*{Contact}
2 | % --------------------------------- %
3 | You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\
4 | \newline
5 | Thank you for attending 42AI's Python Bootcamp module03 !
6 |
7 | % ================================= %
8 | \section*{Acknowledgements}
9 | % --------------------------------- %
10 | The Python bootcamp is the result of a collective work, for which we would like to thank:
11 | \begin{itemize}
12 | \item Maxime Choulika (cmaxime),
13 | \item Pierre Peigné (ppeigne, pierre@42ai.fr),
14 | \item Matthieu David (mdavid, matthieu@42ai.fr),
15 | \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr)
16 | \item Mathieu Perez (maperez, mathieu.perez@42ai.fr)
17 | \end{itemize}
18 | who supervised the creation, the enhancement of the bootcamp and this present transcription.
19 |
20 | \begin{itemize}
21 | \item Louis Develle (ldevelle, louis@42ai.fr)
22 | \item Augustin Lopez (aulopez)
23 | \item Luc Lenotre (llenotre)
24 | \item Owen Roberts (oroberts)
25 | \item Thomas Flahault (thflahau)
26 | \item Amric Trudel (amric@42ai.fr)
27 | \item Baptiste Lefeuvre (blefeuvr@student.42.fr)
28 | \item Mathilde Boivin (mboivin@student.42.fr)
29 | \item Tristan Duquesne (tduquesn@student.42.fr)
30 | \end{itemize}
31 | for your investment in the creation and development of these modules.
32 |
33 | \begin{itemize}
34 | \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps !
35 | \end{itemize}
36 |
37 | \vfill
38 | \doclicenseThis
--------------------------------------------------------------------------------
/module03/subject/en.instructions.tex:
--------------------------------------------------------------------------------
1 | \chapter{Common Instructions}
2 | \begin{itemize}
3 | \item The version of Python recommended to use is 3.7, you can
4 | check the version of Python with the following command: \texttt{python -V}
5 |
6 | \item The norm: during this bootcamp, it is recommended to follow the
7 | \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory.
8 | You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which
9 | is a tool to check your Python code.
10 | \item The function \texttt{eval} is never allowed.
11 | \item The exercises are ordered from the easiest to the hardest.
12 | \item Your exercises are going to be evaluated by someone else,
13 | so make sure that your variable names and function names are appropriate and civil.
14 | \item Your manual is the internet.
15 |
16 | \item If you are a student from 42, you can access our Discord server
17 | on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your
18 | questions to your peers in the dedicated Bootcamp channel.
19 |
20 | \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}.
21 |
22 | \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}.
23 |
24 | \item We encourage you to create test programs for your
25 | project even though this work \textbf{won't have to be
26 | submitted and won't be graded}. It will give you a chance
27 | to easily test your work and your peers’ work. You will find
28 | those tests especially useful during your defence. Indeed,
29 | during defence, you are free to use your tests and/or the
30 | tests of the peer you are evaluating.
31 |
32 | \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\
33 | You can tell us more about your experience with this module by filling \href{https://forms.gle/mBe7sBKq9tJzpDG37}{this form}.\\
34 | Thank you in advance and good luck for this bootcamp !
35 |
36 | \end{itemize}
--------------------------------------------------------------------------------
/module03/subject/en.subject.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module03/subject/en.subject.pdf
--------------------------------------------------------------------------------
/module03/subject/en.subject.tex:
--------------------------------------------------------------------------------
1 | % vim: set ts=4 sw=4 tw=80 noexpandtab:
2 |
3 | \documentclass{42-en}
4 |
5 | %******************************************************************************%
6 | % %
7 | % Prologue %
8 | % %
9 | %******************************************************************************%
10 | \usepackage[
11 | type={CC},
12 | modifier={by-nc-sa},
13 | version={4.0},
14 | ]{doclicense}
15 |
16 | %****************************************************************%
17 | % Re/definition of commands %
18 | %****************************************************************%
19 |
20 | \newcommand{\ailogo}[1]{\def \@ailogo {#1}}\ailogo{assets/42ai_logo.pdf}
21 |
22 | %% Redefine \maketitle
23 | \makeatletter
24 | \def \maketitle {
25 | \begin{titlepage}
26 | \begin{center}
27 | %\begin{figure}[t]
28 | %\includegraphics[height=8cm]{\@ailogo}
29 | \includegraphics[height=8cm]{assets/42ai_logo.pdf}
30 | %\end{figure}
31 | \vskip 5em
32 | {\huge \@title}
33 | \vskip 2em
34 | {\LARGE \@subtitle}
35 | \vskip 4em
36 | \end{center}
37 | %\begin{center}
38 | %\@author
39 | %\end{center}
40 | %\vskip 5em
41 | \vfill
42 | \begin{center}
43 | \emph{\summarytitle : \@summary}
44 | \end{center}
45 | \vspace{2cm}
46 | %\vskip 5em
47 | %\doclicenseThis
48 | \end{titlepage}
49 | }
50 | \makeatother
51 |
52 | \makeatletter
53 | \def \makeheaderfilesforbidden
54 | {
55 | \noindent
56 | \begin{tabularx}{\textwidth}{|X X X X|}
57 | \hline
58 | \multicolumn{1}{|>{\raggedright}m{1cm}|}
59 | {\vskip 2mm \includegraphics[height=1cm]{assets/42ai_logo.pdf}} &
60 | \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } &
61 | \multicolumn{1}{ >{\raggedleft}p{1.5cm}|}
62 | %% {\scriptsize points : \@exscore} \\ \hline
63 | {} \\ \hline
64 |
65 | \multicolumn{4}{|>{\centering}m{15cm}|}
66 | {\small \@extitle} \\ \hline
67 |
68 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
69 | {\small Turn-in directory : \ttfamily
70 | $ex\@exnumber/$ }
71 | \\ \hline
72 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
73 | {\small Files to turn in : \ttfamily \@exfiles }
74 | \\ \hline
75 |
76 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
77 | {\small Forbidden functions : \ttfamily \@exforbidden }
78 | \\ \hline
79 |
80 | %% \multicolumn{4}{|>{\raggedright}m{15cm}|}
81 | %% {\small Remarks : \ttfamily \@exnotes }
82 | %% \\ \hline
83 | \end{tabularx}
84 | %% \exnotes
85 | \exrules
86 | \exmake
87 | \exauthorize{None}
88 | \exforbidden{None}
89 | \extitle{}
90 | \exnumber{}
91 | }
92 | \makeatother
93 |
94 | %% Syntactic highlights
95 | \makeatletter
96 | \newenvironment{pythoncode}{%
97 | \VerbatimEnvironment
98 | \usemintedstyle{emacs}
99 | \minted@resetoptions
100 | \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize}
101 | \begin{figure}[ht!]
102 | \centering
103 | \begin{minipage}{16cm}
104 | \begin{VerbatimOut}{\jobname.pyg}}
105 | {%[
106 | \end{VerbatimOut}
107 | \minted@pygmentize{c}
108 | \DeleteFile{\jobname.pyg}
109 | \end{minipage}
110 | \end{figure}}
111 | \makeatother
112 |
113 | \usemintedstyle{native}
114 |
115 | \begin{document}
116 |
117 | % =============================================================================%
118 | % ===================================== %
119 |
120 | \title{Python Bootcamp - Module 03}
121 | \subtitle{Numpy}
122 | \author{
123 | Maxime Choulika (cmaxime), Pierre Peigné (ppeigne), Matthieu David (mdavid)
124 | }
125 |
126 | \summary
127 | {
128 | Today you will learn how to use the Python library that will allow you to manipulate
129 | multidimensional arrays (vectors) and perform complex mathematical operations on them.
130 | }
131 |
132 | \maketitle
133 | \input{en.instructions.tex}
134 | \newpage
135 | \tableofcontents
136 | \startexercices
137 |
138 | % ===================================== %
139 | % =============================================================================%
140 |
141 |
142 | %******************************************************************************%
143 | % %
144 | % Exercises %
145 | % %
146 | %******************************************************************************%
147 |
148 | % ============================================== %
149 | % ===========================(start ex 00) %
150 | \input{exercises/m03ex00.tex}
151 | % ===========================(fin ex 00) %
152 | % ============================================== %
153 | \newpage
154 | % ============================================== %
155 | % ===========================(start ex 01) %
156 | \input{exercises/m03ex01.tex}
157 | % ===========================(fin ex 01) %
158 | % ============================================== %
159 | \newpage
160 | % ============================================== %
161 | % ===========================(start ex 02) %
162 | \input{exercises/m03ex02.tex}
163 | % ===========================(fin ex 02) %
164 | % ============================================== %
165 | \newpage
166 | % ============================================== %
167 | % ===========================(start ex 03) %
168 | \input{exercises/m03ex03.tex}
169 | % ===========================(fin ex 03) %
170 | % ============================================== %
171 | \newpage
172 |
173 | % ============================================== %
174 | % ===========================(start ex 04) %
175 | \input{exercises/m03ex04.tex}
176 | % ===========================(fin ex 04) %
177 | % ============================================== %
178 | \newpage
179 | % ================================= %
180 | \input{en.acknowledgements.tex}
181 |
182 | \end{document}
--------------------------------------------------------------------------------
/module04/exercises/m04ex00.tex:
--------------------------------------------------------------------------------
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:
--------------------------------------------------------------------------------
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}
46 |
--------------------------------------------------------------------------------
/module04/exercises/m04ex02.tex:
--------------------------------------------------------------------------------
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:
--------------------------------------------------------------------------------
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:
--------------------------------------------------------------------------------
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:
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
/module04/exercises/m04ex06.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 06}
2 | \extitle{MyPlotLib}
3 | \turnindir{ex06}
4 | \exnumber{06}
5 | \exfiles{MyPlotLib.py}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 | % ================================= %
10 | \section*{Objective}
11 | % --------------------------------- %
12 | The goal of this exercise is to introduce you to plotting methods using different
13 | libraries like Pandas, Matplotlib, Seaborn or Scipy.
14 |
15 | % ================================= %
16 | \section*{Instructions}
17 | % --------------------------------- %
18 | This exercise uses the following dataset: \texttt{athlete\_events.csv}\\
19 | \\
20 | Write a class called \texttt{MyPlotLib}. This class implements different plotting
21 | methods, each of which takes two arguments:
22 | \begin{itemize}
23 | \item a pandas.DataFrame which contains the dataset,
24 | \item a list of features names.
25 | \end{itemize}
26 |
27 | \hint{\href{https://towardsdatascience.com/feature-engineering-for-machine-learning-3a5e293a5114}{What is a feature?}}
28 |
29 | \begin{itemize}
30 | \item \texttt{histogram(data, features)}: plots one histogram for each numerical feature in the list,
31 | \item \texttt{density(data, features)}: plots the density curve of each numerical feature in the list,
32 | \item \texttt{pair\_plot(data, features)}: plots a matrix of subplots (also called scatter plot matrix).
33 | On each subplot shows a scatter plot of one numerical variable against another one.
34 | The main diagonal of this matrix shows simple histograms.
35 | \item \texttt{box\_plot(data, features)}: displays a box plot for each numerical variable in the dataset.
36 | \end{itemize}
37 |
38 | % ================================= %
39 | \section*{Examples}
40 | % --------------------------------- %
41 |
42 | \begin{figure}[h!]
43 | \begin{minipage}[l]{0.49\linewidth}
44 | \includegraphics[scale=0.39]{assets/ex06_histogram.png}
45 | \caption{histogram}
46 | \end{minipage}
47 | \hfill
48 | \begin{minipage}[c]{0.49\linewidth}
49 | \includegraphics[scale=0.39]{assets/ex06_density.png}
50 | \caption{density}
51 | \end{minipage}
52 |
53 | \begin{minipage}[l]{0.49\linewidth}
54 | \includegraphics[scale=0.39]{assets/ex06_pair_plot.png}
55 | \caption{pair plot}
56 | \end{minipage}
57 | \hfill
58 | \begin{minipage}[c]{0.49\linewidth}
59 | \includegraphics[scale=0.39]{assets/ex06_box_plot.png}
60 | \caption{box plot}
61 | \end{minipage}
62 | \end{figure}
--------------------------------------------------------------------------------
/module04/exercises/m04ex07.tex:
--------------------------------------------------------------------------------
1 | \chapter{Exercise 07}
2 | \extitle{Komparator}
3 | \turnindir{ex07}
4 | \exnumber{07}
5 | \exfiles{Komparator.py, MyPlotLib.py (optional)}
6 | \exforbidden{None}
7 | \makeheaderfilesforbidden
8 |
9 |
10 | % ================================= %
11 | \section*{Objective}
12 | % --------------------------------- %
13 | The goal of this exercise is to introduce plotting methods among the different
14 | libraries Pandas, Matplotlib, Seaborn or Scipy.
15 |
16 | % ================================= %
17 | \section*{Instructions}
18 | % --------------------------------- %
19 | This exercise uses the following dataset: \texttt{athlete\_events.csv}.\\
20 | \\
21 | Write a class called \texttt{Komparator} whose constructor takes as an argument a pandas.DataFrame which contains the dataset.\\
22 | \\
23 | The class must implement the following methods, which take as input two variable names:
24 | \begin{itemize}
25 | \item \texttt{compare\_box\_plots(self, categorical\_var, numerical\_var)}: displays a series of box plots
26 | to compare how the distribution of the numerical variable changes if we only consider
27 | the subpopulation which belongs to each category.
28 | There should be as many box plots as categories.
29 | For example, with Sex and Height, we would compare
30 | the height distributions of men vs. women with two box plots.
31 | \item \texttt{density(self, categorical\_var, numerical\_var)}: displays the density of the numerical variable.
32 | Each subpopulation should be represented by a separate curve on the graph.
33 | \item \texttt{compare\_histograms(self, categorical\_var, numerical\_var)}: plots the numerical variable in a separate histogram for each category.
34 | As an extra, you can use overlapping histograms with a color code.
35 | \end{itemize}
36 | BONUS: Your functions can also accept a list of numerical variables (instead of just one), and output a comparison plot for each variable in the list.
37 |
--------------------------------------------------------------------------------
/module04/subject/Makefile:
--------------------------------------------------------------------------------
1 | # List the pdf's to build. foo.tex will produce foo.pdf
2 | TARGETS = en.subject.pdf
3 |
4 | # List the files included in the slides
5 | DEPS =
6 |
7 | # Relative path to the LaTeX documentclass setup files
8 | # Adapt as needed
9 | # RELPATH = $(shell git rev-parse --show-toplevel)/resources/latex/
10 | # RELPATH for github actions:
11 | RELPATH = $(shell pwd)/../../resources/latex/
12 |
13 | # You should not touch this either
14 | include $(RELPATH)/Makefile.LaTeX
15 |
--------------------------------------------------------------------------------
/module04/subject/assets/42ai_logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module04/subject/assets/42ai_logo.pdf
--------------------------------------------------------------------------------
/module04/subject/assets/ex06_box_plot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module04/subject/assets/ex06_box_plot.png
--------------------------------------------------------------------------------
/module04/subject/assets/ex06_density.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module04/subject/assets/ex06_density.png
--------------------------------------------------------------------------------
/module04/subject/assets/ex06_histogram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module04/subject/assets/ex06_histogram.png
--------------------------------------------------------------------------------
/module04/subject/assets/ex06_pair_plot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module04/subject/assets/ex06_pair_plot.png
--------------------------------------------------------------------------------
/module04/subject/en.acknowledgements.tex:
--------------------------------------------------------------------------------
1 | \section*{Contact}
2 | % --------------------------------- %
3 | You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\
4 | \newline
5 | Thank you for attending 42AI's Python Bootcamp module04 !
6 |
7 | % ================================= %
8 | \section*{Acknowledgements}
9 | % --------------------------------- %
10 | The Python bootcamp is the result of a collective work, for which we would like to thank:
11 | \begin{itemize}
12 | \item Maxime Choulika (cmaxime),
13 | \item Pierre Peigné (ppeigne, pierre@42ai.fr),
14 | \item Matthieu David (mdavid, matthieu@42ai.fr),
15 | \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr)
16 | \item Mathieu Perez (maperez, mathieu.perez@42ai.fr)
17 | \end{itemize}
18 | who supervised the creation, the enhancement of the bootcamp and this present transcription.
19 |
20 | \begin{itemize}
21 | \item Louis Develle (ldevelle, louis@42ai.fr)
22 | \item Augustin Lopez (aulopez)
23 | \item Luc Lenotre (llenotre)
24 | \item Owen Roberts (oroberts)
25 | \item Thomas Flahault (thflahau)
26 | \item Amric Trudel (amric@42ai.fr)
27 | \item Baptiste Lefeuvre (blefeuvr@student.42.fr)
28 | \item Mathilde Boivin (mboivin@student.42.fr)
29 | \item Tristan Duquesne (tduquesn@student.42.fr)
30 | \end{itemize}
31 | for your investment in the creation and development of these modules.
32 |
33 | \begin{itemize}
34 | \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps !
35 | \end{itemize}
36 |
37 | \vfill
38 | \doclicenseThis
--------------------------------------------------------------------------------
/module04/subject/en.instructions.tex:
--------------------------------------------------------------------------------
1 | \chapter{Common Instructions}
2 | \begin{itemize}
3 | \item The version of Python recommended to use is 3.7, you can
4 | check the version of Python with the following command: \texttt{python -V}
5 |
6 | \item The norm: during this bootcamp, it is recommended to follow the
7 | \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory.
8 | You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which
9 | is a tool to check your Python code.
10 | \item The function \texttt{eval} is never allowed.
11 | \item The exercises are ordered from the easiest to the hardest.
12 | \item Your exercises are going to be evaluated by someone else,
13 | so make sure that your variable names and function names are appropriate and civil.
14 | \item Your manual is the internet.
15 |
16 | \item If you are a student from 42, you can access our Discord server
17 | on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your
18 | questions to your peers in the dedicated Bootcamp channel.
19 |
20 | \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}.
21 |
22 | \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}.
23 |
24 | \item We encourage you to create test programs for your
25 | project even though this work \textbf{won't have to be
26 | submitted and won't be graded}. It will give you a chance
27 | to easily test your work and your peers’ work. You will find
28 | those tests especially useful during your defence. Indeed,
29 | during defence, you are free to use your tests and/or the
30 | tests of the peer you are evaluating.
31 |
32 | \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\
33 | You can tell us more about your experience with this module by filling \href{https://forms.gle/XCTac2mWnm7LAYhGA}{this form}.\\
34 | Thank you in advance and good luck for this bootcamp !
35 |
36 | \end{itemize}
--------------------------------------------------------------------------------
/module04/subject/en.subject.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/module04/subject/en.subject.pdf
--------------------------------------------------------------------------------
/module04/subject/en.subject.tex:
--------------------------------------------------------------------------------
1 | % vim: set ts=4 sw=4 tw=80 noexpandtab:
2 |
3 | \documentclass{42-en}
4 |
5 | %******************************************************************************%
6 | % %
7 | % Prologue %
8 | % %
9 | %******************************************************************************%
10 | \usepackage[
11 | type={CC},
12 | modifier={by-nc-sa},
13 | version={4.0},
14 | ]{doclicense}
15 |
16 | %****************************************************************%
17 | % Re/definition of commands %
18 | %****************************************************************%
19 |
20 | \newcommand{\ailogo}[1]{\def \@ailogo {#1}}\ailogo{assets/42ai_logo.pdf}
21 |
22 | %% Redefine \maketitle
23 | \makeatletter
24 | \def \maketitle {
25 | \begin{titlepage}
26 | \begin{center}
27 | %\begin{figure}[t]
28 | %\includegraphics[height=8cm]{\@ailogo}
29 | \includegraphics[height=8cm]{assets/42ai_logo.pdf}
30 | %\end{figure}
31 | \vskip 5em
32 | {\huge \@title}
33 | \vskip 2em
34 | {\LARGE \@subtitle}
35 | \vskip 4em
36 | \end{center}
37 | %\begin{center}
38 | %\@author
39 | %\end{center}
40 | %\vskip 5em
41 | \vfill
42 | \begin{center}
43 | \emph{\summarytitle : \@summary}
44 | \end{center}
45 | \vspace{2cm}
46 | %\vskip 5em
47 | %\doclicenseThis
48 | \end{titlepage}
49 | }
50 | \makeatother
51 |
52 | \makeatletter
53 | \def \makeheaderfilesforbidden
54 | {
55 | \noindent
56 | \begin{tabularx}{\textwidth}{|X X X X|}
57 | \hline
58 | \multicolumn{1}{|>{\raggedright}m{1cm}|}
59 | {\vskip 2mm \includegraphics[height=1cm]{assets/42ai_logo.pdf}} &
60 | \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } &
61 | \multicolumn{1}{ >{\raggedleft}p{1.5cm}|}
62 | %% {\scriptsize points : \@exscore} \\ \hline
63 | {} \\ \hline
64 |
65 | \multicolumn{4}{|>{\centering}m{15cm}|}
66 | {\small \@extitle} \\ \hline
67 |
68 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
69 | {\small Turn-in directory : \ttfamily
70 | $ex\@exnumber/$ }
71 | \\ \hline
72 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
73 | {\small Files to turn in : \ttfamily \@exfiles }
74 | \\ \hline
75 |
76 | \multicolumn{4}{|>{\raggedright}m{15cm}|}
77 | {\small Forbidden functions : \ttfamily \@exforbidden }
78 | \\ \hline
79 |
80 | %% \multicolumn{4}{|>{\raggedright}m{15cm}|}
81 | %% {\small Remarks : \ttfamily \@exnotes }
82 | %% \\ \hline
83 | \end{tabularx}
84 | %% \exnotes
85 | \exrules
86 | \exmake
87 | \exauthorize{None}
88 | \exforbidden{None}
89 | \extitle{}
90 | \exnumber{}
91 | }
92 | \makeatother
93 |
94 | %% Syntactic highlights
95 | \makeatletter
96 | \newenvironment{pythoncode}{%
97 | \VerbatimEnvironment
98 | \usemintedstyle{emacs}
99 | \minted@resetoptions
100 | \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize}
101 | \begin{figure}[ht!]
102 | \centering
103 | \begin{minipage}{16cm}
104 | \begin{VerbatimOut}{\jobname.pyg}}
105 | {%[
106 | \end{VerbatimOut}
107 | \minted@pygmentize{c}
108 | \DeleteFile{\jobname.pyg}
109 | \end{minipage}
110 | \end{figure}}
111 | \makeatother
112 |
113 | \usemintedstyle{native}
114 |
115 | \begin{document}
116 |
117 | % =============================================================================%
118 | % ===================================== %
119 |
120 | \title{Python Bootcamp - Module 04}
121 | \subtitle{Pandas}
122 | \author{
123 | Maxime Choulika (cmaxime), Pierre Peigné (ppeigne), Matthieu David (mdavid)
124 | }
125 |
126 | \summary
127 | {
128 | Today you will learn how to use a Python library that will allow you
129 | to manipulate gigantic amounts of data: Pandas.
130 | }
131 | \maketitle
132 | \input{en.instructions.tex}
133 | \newpage
134 | \tableofcontents
135 | \startexercices
136 |
137 | % ===================================== %
138 | % =============================================================================%
139 |
140 |
141 | %******************************************************************************%
142 | % %
143 | % Exercises %
144 | % %
145 | %******************************************************************************%
146 |
147 | % ============================================== %
148 | % ===========================(start ex 00) %
149 | \input{exercises/m04ex00.tex}
150 | % ===========================(fin ex 00) %
151 | % ============================================== %
152 | \newpage
153 | % ============================================== %
154 | % ===========================(start ex 01) %
155 | \input{exercises/m04ex01.tex}
156 | % ===========================(fin ex 01) %
157 | % ============================================== %
158 | \newpage
159 | % ============================================== %
160 | % ===========================(start ex 02) %
161 | \input{exercises/m04ex02.tex}
162 | % ===========================(fin ex 02) %
163 | % ============================================== %
164 | \newpage
165 | % ============================================== %
166 | % ===========================(start ex 03) %
167 | \input{exercises/m04ex03.tex}
168 | % ===========================(fin ex 03) %
169 | % ============================================== %
170 | \newpage
171 | % ============================================== %
172 | % ===========================(start ex 04) %
173 | \input{exercises/m04ex04.tex}
174 | % ===========================(fin ex 04) %
175 | % ============================================== %
176 | \newpage
177 | % ============================================== %
178 | % ===========================(start ex 05) %
179 | \input{exercises/m04ex05.tex}
180 | % ===========================(fin ex 05) %
181 | % ============================================== %
182 | \newpage
183 | % ============================================== %
184 | % ===========================(start ex 06) %
185 | \input{exercises/m04ex06.tex}
186 | % ===========================(fin ex 06) %
187 | % ============================================== %
188 | \newpage
189 | % ============================================== %
190 | % ===========================(start ex 07) %
191 | \input{exercises/m04ex07.tex}
192 | % ===========================(fin ex 07) %
193 | % ============================================== %
194 | \newpage
195 | \input{en.acknowledgements.tex}
196 | \end{document}
--------------------------------------------------------------------------------
/resources/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .aux
3 | .log
4 | .out
5 | .pyg
6 | .pyc
7 | .toc
8 | .o
9 | *~
10 | #*#
11 |
--------------------------------------------------------------------------------
/resources/latex/42_logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/resources/latex/42_logo.pdf
--------------------------------------------------------------------------------
/resources/latex/Makefile.LaTeX:
--------------------------------------------------------------------------------
1 | #******************************************************************************#
2 | # #
3 | # Makefile.LaTeX for LaTeX #
4 | # Created on : Mon Oct 5 17:01:29 2015 #
5 | # Make by : Uriel "Korfuri" Corfa #
6 | # Made by : David "Thor" GIRON #
7 | # #
8 | #******************************************************************************#
9 |
10 | RESSOURCE_FILES = $(RELPATH)/Makefile.LaTeX \
11 | $(RELPATH)/atbeginend.sty \
12 | $(RELPATH)/tocloft.sty \
13 | $(RELPATH)/minted.sty \
14 | $(RELPATH)/multirow.sty \
15 | $(RELPATH)/42-fr.cls \
16 | $(RELPATH)/back.pdf \
17 | $(RELPATH)/42_logo.pdf \
18 | $(RELPATH)/info.pdf \
19 | $(RELPATH)/helphint.pdf \
20 | $(RELPATH)/warn.pdf
21 |
22 | ALL_DEPENDENCIES = $(RESSOURCE_FILES) $(DEPS)
23 |
24 | export TEXINPUTS := ..:.:$(RELPATH):${TEXINPUTS}:
25 |
26 | all: $(TARGETS)
27 |
28 | clean:
29 | rm -f *.aux *.ent *.log *.out *.toc *.nav *.snm *.vrb *.pyg *.pdf.version *.fls *.fdb_latexmk
30 |
31 | distclean: clean
32 | rm -f $(TARGETS)
33 |
34 | re: distclean all
35 |
36 | %.pdf: %.tex Makefile $(ALL_DEPENDENCIES)
37 | pdflatex -shell-escape -halt-on-error $<
38 | @if [ $$? = 0 ]; then\
39 | pdflatex -shell-escape -halt-on-error $<;\
40 | echo "Build OK";\
41 | else\
42 | echo "Build Failed";\
43 | exit 1;\
44 | fi
45 |
46 | view: all
47 | (type xpdf > /dev/null 2>&1 && xpdf ${TARGETS}) ||\
48 | (type evince > /dev/null 2>&1 && evince ${TARGETS})
49 |
50 |
51 | #******************************************************************************#
52 |
--------------------------------------------------------------------------------
/resources/latex/Makefile.template:
--------------------------------------------------------------------------------
1 | # List the pdf's to build. foo.tex will produce foo.pdf
2 | TARGETS = foo.pdf
3 |
4 | # List the files included in the slides
5 | DEPS = somePicture.png someSound.flac someOtherPicture.png
6 |
7 | # Relative path to the LaTeX documentclass setup files
8 | # Adapt as needed
9 | RELPATH = $(shell git rev-parse --show-toplevel)/templates/latex/
10 |
11 | # You should not touch this either
12 | include $(RELPATH)/Makefile.LaTeX
13 |
--------------------------------------------------------------------------------
/resources/latex/atbeginend.sty:
--------------------------------------------------------------------------------
1 | % atbeginend.sty
2 | %
3 | % From : http://www.eng.cam.ac.uk/help/tpl/textprocessing/atbeginend.sty
4 | %
5 | % defines
6 | % \BeforeBegin{environment}{code-to-execute}
7 | % \BeforeEnd {environment}{code-to-execute}
8 | % \AfterBegin {environment}{code-to-execute}
9 | % \AfterEnd {environment}{code-to-execute}
10 | %
11 | % Save \begin and \end to \BeginEnvironment and \EndEnvironment
12 | \let\BeginEnvironment=\begin
13 | \let\EndEnvironment=\end
14 |
15 | \def\IfUnDef#1{\expandafter\ifx\csname#1\endcsname\relax}
16 |
17 | % Null command needed to for \nothing{something}=.nothing.
18 | \def\NullCom#1{}
19 |
20 | \def\begin#1{%
21 | %
22 | % if defined \BeforeBeg for this environment, execute it
23 | \IfUnDef{BeforeBeg#1}\else\csname BeforeBeg#1\endcsname\fi%
24 | %
25 | %
26 | %
27 | \IfUnDef{AfterBeg#1}% This is done to skip the command for environments
28 | % which can take arguments, like multicols; YOU MUST NOT
29 | % USE \AfterBegin{...}{...} for such environments!
30 | \let\SaveBegEng=\BeginEnvironment%
31 | \else%
32 | % Start this environment
33 | \BeginEnvironment{#1}%
34 | % and execute code after \begin{environment}
35 | \csname AfterBeg#1\endcsname%
36 | %
37 | \let\SaveBegEng=\NullCom%
38 | \fi%
39 | \SaveBegEng{#1}%
40 | }
41 |
42 |
43 | \def\end#1{%
44 | %
45 | % execute code before \end{environment}
46 | \IfUnDef{BeforeEnd#1}\else\csname BeforeEnd#1\endcsname\fi%
47 | %
48 | % close this environment
49 | \EndEnvironment{#1}%
50 | %
51 | % and execute code after \begin{environment}
52 | \IfUnDef{AfterEnd#1}\else\csname AfterEnd#1\endcsname\fi%
53 | }
54 |
55 |
56 | %% Now, define commands
57 | % \BeforeBegin{environment}{code-to-execute}
58 | % \BeforeEnd {environment}{code-to-execute}
59 | % \AfterBegin {environment}{code-to-execute}
60 | % \AfterEnd {environment}{code-to-execute}
61 |
62 | \def\BeforeBegin#1#2{\expandafter\gdef\csname BeforeBeg#1\endcsname
63 | {#2}}
64 | \def\BeforeEnd #1#2{\expandafter\gdef\csname BeforeEnd#1\endcsname
65 | {#2}}
66 | \def\AfterBegin #1#2{\expandafter\gdef\csname AfterBeg#1\endcsname {#2}}
67 | \def\AfterEnd #1#2{\expandafter\gdef\csname AfterEnd#1\endcsname{#2}}
68 |
--------------------------------------------------------------------------------
/resources/latex/back.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/resources/latex/back.pdf
--------------------------------------------------------------------------------
/resources/latex/dark-42_logo.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/resources/latex/dark-42_logo.pdf
--------------------------------------------------------------------------------
/resources/latex/dark-back.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/resources/latex/dark-back.pdf
--------------------------------------------------------------------------------
/resources/latex/helphint.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/resources/latex/helphint.pdf
--------------------------------------------------------------------------------
/resources/latex/info.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/resources/latex/info.pdf
--------------------------------------------------------------------------------
/resources/latex/multirow.sty:
--------------------------------------------------------------------------------
1 | %%
2 | %% multirow.sty V1.6 version (5-May-2004)
3 | %%
4 | %% Author: Jerry Leichter
5 | %% Piet van Oostrum
6 | %%
7 | %% This file may be distributed under the terms of the LaTeX Project Public
8 | %% License, as described in lppl.txt in the base LaTeX distribution.
9 | %% Either version 1 or, at your option, any later version.
10 | %%
11 | %% V1.0 was distributed anonymously, based on a Usenet posting that was
12 | %% not intended for stand-alone use.
13 | %% V1.1 was modified by Piet van Oostrum to allow it to
14 | %% work without bigstrut.sty.
15 | %% V1.2 was modified by Jerry Leichter for the same goal, but using a
16 | %% different approach which will work properly in conjunction with
17 | %% bigstrut.sty.
18 | %% V1.2a was modified by Piet van Oostrum to use \vskip
19 | %% instead of \raise in positioning, avoiding making rows too high
20 | %% when the adjustment is large.
21 | %% V1.3 was modified by Piet van Oostrum to work properly in a p{} column
22 | %% (\leavevmode added)
23 | %% V1.4 was modified by Piet van Oostrum to check for the special case that
24 | %% the width is given as an *. In this case the natural
25 | %% width of the text argument will be used and the argument
26 | %% is processed in LR-mode.
27 | %% V1.5 was modified by Piet van Oostrum: Added a % after \hbox{#5}\vfill}.
28 | %% Added \struts around #5 for better vertical positioning.
29 | %% Additional coding for negative value of nrows.
30 | %% V1.6 was modified by Piet van Oostrum: Replace a space by \relax after
31 | %% \advance\@tempdima#4.
32 | %%
33 | % Make an entry that will span multiple rows of a table.
34 | %
35 | % \multirow{nrows}[bigstruts]{width}[fixup]{text}
36 | %
37 | % nrows is the number of rows to span. It's up to you to leave the other
38 | % rows empty, or the stuff created by \multirow will over-write it.
39 | % With a positive value of nrows the spanned colomns are this row and
40 | % (nrows-1) rows below it. With a negative value of nrows they are
41 | % this row and (1-nrows) above it.
42 | %
43 | % bigstruts is mainly used if you've used bigstrut.sty. In that case it
44 | % is the total number of uses of \bigstrut within the rows being
45 | % spanned. Count 2 uses for each \bigstrut, 1 for each \bigstrut[x]
46 | % where x is either t or b. The default is 0.
47 | % width is the width to which the text is to be set, or * to indicate that
48 | % the text argument's natural width is to be used.
49 | %
50 | % text is the actual text. If the width was set explicitly, the text will
51 | % be set in a parbox of that width; you can use \\ to force linebreaks
52 | % where you like.
53 | %
54 | % If the width was given as * the text will be set in LR mode. If you
55 | % want a multiline entry in this case you should use a tabular or array
56 | % in the text parameter.
57 | %
58 | % The text is centered vertically within the range spanned by nrows.
59 | %
60 | % fixup is a length used for fine tuning: The text will be raised (or
61 | % lowered, if fixup is negative) by that length above (below) wherever
62 | % it would otherwise have gone.
63 | %
64 | % For example (using both multirow and bigstrut)
65 | %
66 | % \newcommand{\minitab}[2][l]{\begin{tabular}{#1}#2\end{tabular}}
67 | % \begin{tabular}{|c|c|}
68 | % \hline
69 | % \multirow{4}{1in}{Common g text} & Column g2a\\
70 | % & Column g2b \\
71 | % & Column g2c \\
72 | % & Column g2d \\
73 | % \hline
74 | % \multirow{3}[6]*{Common g text} & Column g2a\bigstrut\\\cline{2-2}
75 | % & Column g2b \bigstrut\\\cline{2-2}
76 | % & Column g2c \bigstrut\\
77 | % \hline
78 | % \multirow{4}[8]{1in}{Common g text} & Column g2a\bigstrut\\\cline{2-2}
79 | % & Column g2b \bigstrut\\\cline{2-2}
80 | % & Column g2c \bigstrut\\\cline{2-2}
81 | % & Column g2d \bigstrut\\
82 | % \hline
83 | % \multirow{4}*{\minitab[c]{Common \\ g text}} & Column g2a\\
84 | % & Column g2b \\
85 | % & Column g2c \\
86 | % & Column g2d \\
87 | % \hline
88 | % \end{tabular}
89 | %
90 | % If any of the spanned rows are unusually large, or if you're using
91 | % bigstrut.sty and \bigstrut's are used assymetrically about the centerline of
92 | % the spanned rows, the vertical centering may not come out right. Use the
93 | % fixup argument in this case.
94 | %
95 | % Just before "text" is expanded, the \multirowsetup macro is expanded to
96 | % set up any special environment. Initially, \multirowsetup contains just
97 | % \raggedright. It can be redefined with \renewcommand.
98 | %
99 | % Bugs: It's just about impossible to deal correctly with descenders. The
100 | % text will be set up centered, but it may then have a baseline that doesn't
101 | % match the baseline of the stuff beside it, in particular if the stuff
102 | % beside it has descenders and "text" does not. This may result in a small
103 | % missalignment. About all that can be done is to do a final touchup on
104 | % "text", using the fixup optional argument. (Hint: If you use a measure
105 | % like .1ex, there's a reasonable chance that the fixup will still be correct
106 | % if you change the point size.)
107 | %
108 | % \multirow is mainly designed for use with table, as opposed to array,
109 | % environments. It will not work well in an array environment since the lines
110 | % have an extra \jot of space between them which it won't account for. Fixing
111 | % this is difficult in general, and doesn't seem worth it. The bigstruts
112 | % argument can be used to provide a semi-automatic fix: First set
113 | % \bigstrutjot to .5\jot. Then simply repeat nrows as the bigstruts argument.
114 | % This will be close, but probably not exact; you can use the fixup argument
115 | % to refine the result. (If you do this repeatedly, you'll probably want to
116 | % wrap these steps up in a simple macro. Note that the modified \bigstrutjot
117 | % value will not give reasonable results if you have bigstruts and use this
118 | % argument for its intended purpose elsewhere. In that case, you might want
119 | % to set it locally.)
120 | %
121 | % If you use \multirow with the colortbl package you have to take
122 | % precautions if you want to color the column that has the \multirow in it.
123 | % colortbl works by coloring each cell separately. So if you use \multirow
124 | % with a positive nrows value, colortbl will first color the top cell, then
125 | % \multirow will typeset nrows cells starting with this cell, and later
126 | % colortbl will color the other cells, effectively hiding the text in that
127 | % area. This can be solved by putting the \multirow is the last row with a
128 | % negative nrows value.
129 | % Example:
130 | %
131 | % \begin{tabular}{l>{\columncolor{yellow}}l}
132 | % aaaa & \\
133 | % cccc & \\
134 | % dddd & \multirow{-3}*{bbbb}\\
135 | % \end{tabular}
136 | %
137 | \def\multirowsetup{\raggedright}
138 | \def\multirow#1{\relax\@ifnextchar
139 | [{\@multirow{#1}}{\@multirow{#1}[0]}}
140 | \def\@multirow#1[#2]#3{\@ifnextchar [{\@xmultirow{#1}[#2]{#3}}%
141 | {\@xmultirow{#1}[#2]{#3}[0pt]}}
142 | \def\@xmultirow#1[#2]#3[#4]#5{\@tempcnta=#1%
143 | \@tempdima\@tempcnta\ht\@arstrutbox
144 | \advance\@tempdima\@tempcnta\dp\@arstrutbox
145 | \ifnum\@tempcnta<0\@tempdima=-\@tempdima\fi
146 | \advance\@tempdima#2\bigstrutjot
147 | \if*#3\setbox0\vtop to \@tempdima{\vfill\multirowsetup
148 | \hbox{\strut#5\strut}\vfill}%
149 | \else
150 | \setbox0\vtop to \@tempdima{\hsize#3\@parboxrestore
151 | \vfill \multirowsetup \strut#5\strut\par\vfill}%
152 | \fi
153 | \ht0\z@\dp0\z@
154 | \ifnum\@tempcnta<0\advance\@tempdima-\dp\@arstrutbox
155 | \else\@tempdima=\ht\@arstrutbox
156 | \ifnum#2>0 \advance\@tempdima\bigstrutjot \fi
157 | \fi
158 | \advance\@tempdima#4\relax\leavevmode\vtop{\vskip-\@tempdima\box0\vss}}
159 | \@ifundefined{bigstrutjot}{\newdimen\bigstrutjot \bigstrutjot\jot}{}
160 |
--------------------------------------------------------------------------------
/resources/latex/warn.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/42-AI/bootcamp_python/e14f4fbab3505a5815bf1b6e6135db686a698403/resources/latex/warn.pdf
--------------------------------------------------------------------------------
/version:
--------------------------------------------------------------------------------
1 | 3.3.0
--------------------------------------------------------------------------------