├── .gitignore ├── README.md ├── _config.yml ├── binary ├── binary-1.pdf ├── binary-1.tex ├── binary-2.pdf ├── binary-2.tex ├── binary_I.py ├── binary_II.py ├── binary_cours.py ├── fig-binary-1.tikz ├── fig-binary-2.tikz ├── fig-binary-3.tikz └── fig-binary-4.tikz ├── bitcoin ├── bitcoin.pdf ├── bitcoin.py ├── bitcoin.tex ├── bitcoin_lesson_time.py ├── fig-bitcoin-1.tikz ├── fig-bitcoin-2.tikz ├── fig-bitcoin-3.tikz ├── fig-bitcoin-4.tikz └── proof_of_work.py ├── blocks ├── blocks.pdf ├── blocks.tex ├── blocks_circular.py ├── blocks_circular_move.py ├── blocks_idees.py ├── blocks_vertical.py ├── blocks_vertical_move.py ├── fig-blocks-0.tikz ├── fig-blocks-1.tikz ├── fig-blocks-2.tikz ├── fig-blocks-3.tikz ├── fig-blocks-tree1.tikz ├── screen-blocks-bloc0.png ├── screen-blocks-bloc00.png ├── screen-blocks-bloc1-en.png ├── screen-blocks-bloc1.png ├── screen-blocks-bloc2.png ├── screen-blocks-lesson-move-en.png ├── screen-blocks-lesson-move.png ├── screen-blocks-tree00.png ├── screen-blocks-tree1.png ├── screen-blocks-tree2-en.png ├── screen-blocks-tree2.png └── tkinter_move.py ├── book-python1-print.pdf ├── book-python1-print.tex ├── book-python1.pdf ├── book-python1.tex ├── code ├── code.pdf └── code.tex ├── cover ├── cover.txt ├── cover_old │ ├── AlteDin1451Mittelschrift.ttf │ ├── exo7_logo_couleurs.pdf │ ├── exo7_logo_couleurs.tex │ ├── exo7_logo_white.pdf │ ├── exo7_logo_white.tex │ ├── logo-python.png │ ├── python-logo-en.pdf │ ├── python-logo-en.png │ ├── python-logo-en.tex │ ├── python-logo.pdf │ ├── python-logo.svg │ ├── python-logo.tex │ ├── python-logo.tikz │ ├── python_cover.tex │ ├── python_cover2.tex │ ├── python_cover3.tex │ ├── python_cover4.tex │ ├── python_cover_en1.pdf │ ├── python_cover_en1.tex │ └── serpent.tikz ├── exo7-logo-white.svg ├── exo7-logo.svg ├── hilbert_curve.svg ├── python-logo-en-exo7.png ├── python-logo-en-exo7.svg ├── python-logo-exo7.png ├── python-logo-exo7.svg ├── python-logo.png ├── python-logo.svg ├── python1-en-cover-kdp.pdf ├── python1-en-cover-kdp.svg └── python1-en-cover1.svg ├── files ├── averages.txt ├── cities_lat_long.txt ├── cities_lat_long_distances.txt ├── cities_xy.txt ├── cities_xy_distances.txt ├── fig-france.tikz ├── files.pdf ├── files.tex ├── files_1.py ├── files_2.py ├── files_3.py ├── files_4.py ├── files_lesson.py ├── grades.txt ├── image_bw.pbm ├── image_col.ppm ├── image_col_gray.pgm ├── image_gray.pgm ├── lesson-image_bw.pbm ├── lesson-image_col.ppm ├── lesson-image_gray.pgm ├── my_file.txt ├── sales.csv ├── screen-files-1a.png ├── screen-files-1b.png ├── screen-files-2a.png ├── screen-files-2b-en.png ├── screen-files-2b.png ├── screen-files-2c-en.png ├── screen-files-2c.png ├── screen-files-4a.png ├── screen-files-4b.png ├── screen-files-4c.png ├── screen-files-4d.png ├── screen-files-lesson-1-en.png ├── screen-files-lesson-1.png ├── screen-image_coul.png ├── screen-image_coul_gris.png ├── screen-image_gris.png ├── screen-image_nb.png ├── screen-lesson-image_coul.png ├── screen-lesson-image_gris.png ├── screen-lesson-image_nb.png ├── screen-simple_nb.png ├── screen-simple_nb_inverse.png ├── simple_bw.pbm └── simple_bw_inverse.pbm ├── find ├── find.pdf ├── find.tex ├── find_1.py ├── find_2.py ├── find_3.py └── find_4.py ├── functions ├── fig-functions-lesson-1.tikz ├── fig-functions-lesson-2.tikz ├── fig-functions-lesson-3.tikz ├── fig-functions-lesson-4.tikz ├── functions.pdf ├── functions.tex ├── functions_1.py ├── functions_2.py ├── functions_3.py ├── functions_4.py ├── functions_5.py ├── functions_lesson.py └── screen-functions-tortue.png ├── guide ├── ecran-markdown-8.png ├── ecran-markdown-8.tikz ├── fig-arbre.tikz ├── fig-tableau.tikz ├── guide-biblio.pdf ├── guide-biblio.tex ├── guide-functions.pdf ├── guide-functions.tex ├── guide-python.pdf ├── guide-python.tex ├── guide_erreur.py ├── guide_format.py ├── guide_python.py ├── screen-markdown-8-en.png └── screen-markdown-8-en.tikz ├── hello_world ├── fig_hello_world_loop_for.tikz ├── fig_trapezoid.tikz ├── hello_world.pdf ├── hello_world.tex ├── hello_world_1.py ├── hello_world_2.py ├── hello_world_3.py ├── hello_world_4.py ├── hello_world_5.py └── test_period.py ├── ifthen ├── fig-ifthen-0.tikz ├── fig-ifthen-1.tikz ├── fig-ifthen-3.tikz ├── fig-ifthen-lesson-1.tikz ├── fig-ifthen-lesson-2.tikz ├── ifthen.pdf ├── ifthen.tex ├── ifthen_1.py ├── ifthen_2.py ├── ifthen_3.py ├── ifthen_4.py ├── ifthen_5.py ├── ifthen_lesson.py ├── ifthen_lesson_input.py └── screen-ifthen-2.png ├── images ├── fig-images-1.tikz ├── fig-images-2.tikz ├── fig-images-2bis.tikz ├── fig-images-3.tikz ├── gimp_to_pgm.py ├── images.pdf ├── images.py ├── images.tex ├── images_chapter │ ├── cat_gimp_new_photo_0.pgm │ ├── cat_gimp_new_photo_0.png │ ├── cat_gimp_new_photo_1.pgm │ ├── cat_gimp_new_photo_1.png │ ├── cat_gimp_new_photo_2.pgm │ ├── cat_gimp_new_photo_2.png │ ├── cat_gimp_new_photo_3.pgm │ ├── cat_gimp_new_photo_3.png │ ├── cat_gimp_new_photo_4.pgm │ ├── cat_gimp_new_photo_4.png │ ├── cat_gimp_new_photo_5.pgm │ ├── cat_gimp_new_photo_5.png │ ├── cat_gimp_new_photo_6.pgm │ ├── cat_gimp_new_photo_6.png │ ├── cat_gimp_new_photo_7.pgm │ ├── cat_gimp_new_photo_7.png │ ├── cat_gimp_new_photo_8.pgm │ ├── cat_gimp_new_photo_8.png │ ├── clock_gimp_new_baker_0.pgm │ ├── clock_gimp_new_baker_0.png │ ├── clock_gimp_new_baker_1.pgm │ ├── clock_gimp_new_baker_1.png │ ├── clock_gimp_new_baker_15.pgm │ ├── clock_gimp_new_baker_15.png │ ├── clock_gimp_new_baker_16.pgm │ ├── clock_gimp_new_baker_16.png │ ├── clock_gimp_new_baker_17.pgm │ ├── clock_gimp_new_baker_17.png │ ├── clock_gimp_new_baker_2.pgm │ ├── clock_gimp_new_baker_2.png │ ├── clock_gimp_new_baker_3.pgm │ ├── clock_gimp_new_baker_3.png │ ├── clock_gimp_new_baker_4.pgm │ ├── clock_gimp_new_baker_4.png │ ├── clock_gimp_new_baker_5.pgm │ ├── clock_gimp_new_baker_5.png │ ├── pi_gimp_new_photo_0.pgm │ ├── pi_gimp_new_photo_0.png │ ├── pi_gimp_new_photo_1.pgm │ ├── pi_gimp_new_photo_1.png │ ├── pi_gimp_new_photo_2.pgm │ ├── pi_gimp_new_photo_2.png │ ├── pi_gimp_new_photo_3.pgm │ ├── pi_gimp_new_photo_3.png │ ├── pi_gimp_new_photo_4.pgm │ ├── pi_gimp_new_photo_4.png │ ├── pi_gimp_new_photo_5.pgm │ ├── pi_gimp_new_photo_5.png │ ├── pi_gimp_new_photo_6.pgm │ ├── pi_gimp_new_photo_6.png │ ├── pi_gimp_new_photo_7.pgm │ ├── pi_gimp_new_photo_7.png │ ├── pi_gimp_new_photo_8.pgm │ ├── pi_gimp_new_photo_8.png │ ├── surf_gimp_new_baker_0.pgm │ ├── surf_gimp_new_baker_0.png │ ├── surf_gimp_new_baker_1.pgm │ ├── surf_gimp_new_baker_1.png │ ├── surf_gimp_new_baker_12.pgm │ ├── surf_gimp_new_baker_12.png │ ├── surf_gimp_new_baker_13.pgm │ ├── surf_gimp_new_baker_13.png │ ├── surf_gimp_new_baker_14.pgm │ ├── surf_gimp_new_baker_14.png │ ├── surf_gimp_new_baker_15.pgm │ ├── surf_gimp_new_baker_15.png │ ├── surf_gimp_new_baker_2.pgm │ ├── surf_gimp_new_baker_2.png │ ├── surf_gimp_new_baker_3.pgm │ ├── surf_gimp_new_baker_3.png │ ├── surf_gimp_new_baker_4.pgm │ └── surf_gimp_new_baker_4.png ├── images_files.py ├── input │ ├── cat_gimp.pgm │ ├── cat_gimp_new.pgm │ ├── cat_original.jpg │ ├── clock-original.jpg │ ├── clock_gimp.pgm │ ├── clock_gimp_new.pgm │ ├── ecran-test-pgm.png │ ├── image_gray.pgm │ ├── pi-original.jpg │ ├── pi_gimp.pgm │ ├── pi_gimp_new.pgm │ ├── surf-original.png │ ├── surf_gimp.pgm │ ├── surf_gimp_new.pgm │ └── test.pgm └── output │ ├── chat_gimp_new_baker_0.pgm │ ├── chat_gimp_new_baker_1.pgm │ ├── chat_gimp_new_baker_10.pgm │ ├── chat_gimp_new_baker_11.pgm │ ├── chat_gimp_new_baker_12.pgm │ ├── chat_gimp_new_baker_13.pgm │ ├── chat_gimp_new_baker_14.pgm │ ├── chat_gimp_new_baker_15.pgm │ ├── chat_gimp_new_baker_16.pgm │ ├── chat_gimp_new_baker_17.pgm │ ├── chat_gimp_new_baker_2.pgm │ ├── chat_gimp_new_baker_3.pgm │ ├── chat_gimp_new_baker_4.pgm │ ├── chat_gimp_new_baker_5.pgm │ ├── chat_gimp_new_baker_6.pgm │ ├── chat_gimp_new_baker_7.pgm │ ├── chat_gimp_new_baker_8.pgm │ ├── chat_gimp_new_baker_9.pgm │ ├── chat_gimp_new_photo_0.pgm │ ├── chat_gimp_new_photo_1.pgm │ ├── chat_gimp_new_photo_2.pgm │ ├── chat_gimp_new_photo_3.pgm │ ├── chat_gimp_new_photo_4.pgm │ ├── chat_gimp_new_photo_5.pgm │ ├── chat_gimp_new_photo_6.pgm │ ├── chat_gimp_new_photo_7.pgm │ ├── chat_gimp_new_photo_8.pgm │ ├── image_gray_baker_0.pgm │ ├── image_gray_baker_1.pgm │ ├── image_gray_baker_10.pgm │ ├── image_gray_baker_11.pgm │ ├── image_gray_baker_12.pgm │ ├── image_gray_baker_13.pgm │ ├── image_gray_baker_14.pgm │ ├── image_gray_baker_15.pgm │ ├── image_gray_baker_16.pgm │ ├── image_gray_baker_17.pgm │ ├── image_gray_baker_2.pgm │ ├── image_gray_baker_3.pgm │ ├── image_gray_baker_4.pgm │ ├── image_gray_baker_5.pgm │ ├── image_gray_baker_6.pgm │ ├── image_gray_baker_7.pgm │ ├── image_gray_baker_8.pgm │ ├── image_gray_baker_9.pgm │ ├── image_gray_photo_0.pgm │ ├── image_gray_photo_1.pgm │ ├── image_gray_photo_2.pgm │ ├── image_gray_photo_3.pgm │ ├── image_gray_photo_4.pgm │ ├── image_gray_photo_5.pgm │ ├── image_gray_photo_6.pgm │ ├── image_gray_photo_7.pgm │ ├── image_gray_photo_8.pgm │ ├── image_gris_baker_1.pgm │ ├── image_gris_baker_10.pgm │ ├── image_gris_baker_11.pgm │ ├── image_gris_baker_12.pgm │ ├── image_gris_baker_13.pgm │ ├── image_gris_baker_14.pgm │ ├── image_gris_baker_15.pgm │ ├── image_gris_baker_16.pgm │ ├── image_gris_baker_17.pgm │ ├── image_gris_baker_2.pgm │ ├── image_gris_baker_3.pgm │ ├── image_gris_baker_4.pgm │ ├── image_gris_baker_5.pgm │ ├── image_gris_baker_6.pgm │ ├── image_gris_baker_7.pgm │ ├── image_gris_baker_8.pgm │ ├── image_gris_baker_9.pgm │ ├── image_gris_photo_0.pgm │ ├── image_gris_photo_1.pgm │ ├── image_gris_photo_2.pgm │ ├── image_gris_photo_3.pgm │ ├── image_gris_photo_4.pgm │ ├── image_gris_photo_5.pgm │ ├── image_gris_photo_6.pgm │ ├── image_gris_photo_7.pgm │ ├── image_gris_photo_8.pgm │ ├── pi_gimp_new_baker_1.pgm │ ├── pi_gimp_new_baker_10.pgm │ ├── pi_gimp_new_baker_11.pgm │ ├── pi_gimp_new_baker_12.pgm │ ├── pi_gimp_new_baker_13.pgm │ ├── pi_gimp_new_baker_14.pgm │ ├── pi_gimp_new_baker_15.pgm │ ├── pi_gimp_new_baker_16.pgm │ ├── pi_gimp_new_baker_17.pgm │ ├── pi_gimp_new_baker_2.pgm │ ├── pi_gimp_new_baker_3.pgm │ ├── pi_gimp_new_baker_4.pgm │ ├── pi_gimp_new_baker_5.pgm │ ├── pi_gimp_new_baker_6.pgm │ ├── pi_gimp_new_baker_7.pgm │ ├── pi_gimp_new_baker_8.pgm │ ├── pi_gimp_new_baker_9.pgm │ ├── pi_gimp_new_photo_0.pgm │ ├── pi_gimp_new_photo_1.pgm │ ├── pi_gimp_new_photo_2.pgm │ ├── pi_gimp_new_photo_3.pgm │ ├── pi_gimp_new_photo_4.pgm │ ├── pi_gimp_new_photo_5.pgm │ ├── pi_gimp_new_photo_6.pgm │ ├── pi_gimp_new_photo_7.pgm │ ├── pi_gimp_new_photo_8.pgm │ ├── reveil_gimp_new_baker_0.pgm │ ├── reveil_gimp_new_baker_1.pgm │ ├── reveil_gimp_new_baker_10.pgm │ ├── reveil_gimp_new_baker_11.pgm │ ├── reveil_gimp_new_baker_12.pgm │ ├── reveil_gimp_new_baker_13.pgm │ ├── reveil_gimp_new_baker_14.pgm │ ├── reveil_gimp_new_baker_15.pgm │ ├── reveil_gimp_new_baker_16.pgm │ ├── reveil_gimp_new_baker_17.pgm │ ├── reveil_gimp_new_baker_2.pgm │ ├── reveil_gimp_new_baker_3.pgm │ ├── reveil_gimp_new_baker_4.pgm │ ├── reveil_gimp_new_baker_5.pgm │ ├── reveil_gimp_new_baker_6.pgm │ ├── reveil_gimp_new_baker_7.pgm │ ├── reveil_gimp_new_baker_8.pgm │ ├── reveil_gimp_new_baker_9.pgm │ ├── surf_gimp_new_baker_0.pgm │ ├── surf_gimp_new_baker_1.pgm │ ├── surf_gimp_new_baker_10.pgm │ ├── surf_gimp_new_baker_11.pgm │ ├── surf_gimp_new_baker_12.pgm │ ├── surf_gimp_new_baker_13.pgm │ ├── surf_gimp_new_baker_14.pgm │ ├── surf_gimp_new_baker_15.pgm │ ├── surf_gimp_new_baker_2.pgm │ ├── surf_gimp_new_baker_3.pgm │ ├── surf_gimp_new_baker_4.pgm │ ├── surf_gimp_new_baker_5.pgm │ ├── surf_gimp_new_baker_6.pgm │ ├── surf_gimp_new_baker_7.pgm │ ├── surf_gimp_new_baker_8.pgm │ ├── surf_gimp_new_baker_9.pgm │ └── test.pgm ├── life ├── fig-life-0a.tikz ├── fig-life-0b.tikz ├── fig-life-0c.tikz ├── fig-life-0d.tikz ├── fig-life-1.tikz ├── fig-life-4a.tikz ├── fig-life-4b.tikz ├── life-tkinter-mouse.py ├── life.pdf ├── life.tex ├── life_1.py ├── life_2.py ├── life_3.py ├── life_4.py ├── screen-life-0.png ├── screen-life-2-en.png ├── screen-life-2.png ├── screen-life-4a-en.png ├── screen-life-4a.png ├── screen-life-4b-en.png └── screen-life-4b.png ├── lists ├── fig-lists-1.tikz ├── fig-lists-2.tikz ├── fig-lists-3.tikz ├── fig-lists-4.tikz ├── fig-lists-5.tikz ├── fig-lists-I-tir.tikz ├── lists-1.pdf ├── lists-1.tex ├── lists-2.pdf ├── lists-2.tex ├── lists_II_1.py ├── lists_II_2.py ├── lists_II_3.py ├── lists_II_4.py ├── lists_II_lesson.py ├── lists_I_1.py ├── lists_I_2.py ├── lists_I_3.py ├── lists_I_4.py ├── lists_I_5.py ├── lists_I_lesson.py ├── screen-lists-I-tir-bis.png ├── screen-lists-I-tir.png ├── screen-lists-lesson-visualization-bis.png └── screen-lists-lesson-visualization.png ├── lsystems ├── fig-brackets.tikz ├── fig-stacks.tikz ├── lsystems.pdf ├── lsystems.py ├── lsystems.tex ├── optional_argument.py ├── pres-lsystems.pdf ├── screen-lsystems-1.png ├── screen-lsystems-10.png ├── screen-lsystems-11.png ├── screen-lsystems-12.png ├── screen-lsystems-13.png ├── screen-lsystems-14.png ├── screen-lsystems-15.png ├── screen-lsystems-16.png ├── screen-lsystems-17.png ├── screen-lsystems-18.png ├── screen-lsystems-2.png ├── screen-lsystems-3a.png ├── screen-lsystems-3b.png ├── screen-lsystems-3c.png ├── screen-lsystems-3d.png ├── screen-lsystems-3e.png ├── screen-lsystems-4.png ├── screen-lsystems-5.png ├── screen-lsystems-6.png ├── screen-lsystems-7a.png ├── screen-lsystems-7b.png ├── screen-lsystems-7c.png ├── screen-lsystems-7d.png ├── screen-lsystems-7e.png ├── screen-lsystems-8.png └── screen-lsystems-9.png ├── markdown ├── hyphenation_project.py ├── lesson_tkinter_text.py ├── markdown1.md ├── markdown2.md ├── markdown_1.py ├── markdown_2.py ├── markdown_3.py ├── markdown_3_graphics.py ├── markdown_project.py ├── screen-coupures-1.png ├── screen-coupures-2.png ├── screen-coupures-3.png ├── screen-coupures-4.png ├── screen-hyphen-1.png ├── screen-hyphen-2.png ├── screen-hyphen-3.png ├── screen-hyphen-4.png ├── screen-markdown-1-en.png ├── screen-markdown-1.png ├── screen-markdown-2-en.png ├── screen-markdown-2.png ├── screen-markdown-3-en.png ├── screen-markdown-3.png ├── screen-markdown-4-en.png ├── screen-markdown-4.png ├── screen-markdown-5-en.png ├── screen-markdown-5.png ├── screen-markdown-6-en.png ├── screen-markdown-6.png ├── screen-markdown-7-en.png ├── screen-markdown-7.png ├── screen-markdown-8-en.png ├── screen-markdown-8-en.tikz ├── screen-markdown-8.png ├── screen-markdown-8.tikz ├── text_markdown.pdf └── text_markdown.tex ├── misc ├── 4eme_couverture.txt ├── base-fin.svg ├── base-titre.svg ├── chapters.txt ├── fig-part-lsystem.tikz ├── logo_exo7.png ├── logo_exo7.svg ├── postface_book_python.tex └── preface_book_python.tex ├── proba ├── proba.pdf ├── proba.py └── proba.tex ├── python-common.sty ├── python-minimal.sty ├── python-print.sty ├── python-screen.sty ├── python.sty ├── ramsey ├── fig-ramsey-0a.tikz ├── fig-ramsey-0b.tikz ├── fig-ramsey-0c.tikz ├── fig-ramsey-1a.tikz ├── fig-ramsey-1c.tikz ├── fig-ramsey-2.tikz ├── fig-ramsey-4a.tikz ├── fig-ramsey-4b.tikz ├── fig-ramsey-5.tikz ├── fig-ramsey-6.tikz ├── ramsey.pdf ├── ramsey.tex ├── ramsey_1.py ├── ramsey_2.py ├── ramsey_3.py ├── ramsey_4.py ├── ramsey_5.py ├── ramsey_6.py ├── screen-ramsey-1a.png ├── screen-ramsey-1b.png ├── screen-ramsey-1c.png ├── screen-ramsey-1d.png ├── screen-ramsey-2-en.png └── screen-ramsey-2.png ├── stacks ├── fig-sort1.tikz ├── fig-sort2.tikz ├── fig-sort3.tikz ├── fig-sort4.tikz ├── fig-sort5.tikz ├── fig-stacks1.tikz ├── fig-stacks2.tikz ├── fig-stacks3.tikz ├── polish1.tikz ├── polish2.tikz ├── stacks.pdf ├── stacks.tex ├── stacks_1.py ├── stacks_2.py ├── stacks_3.py ├── stacks_4.py ├── stacks_5.py ├── stacks_6.py └── stacks_lesson.py ├── statistics ├── fig-stat-arc.tikz ├── fig-stat-boite.tikz ├── fig-stat-lesson-intro.tikz ├── lesson_tkinter_buttons.py ├── lesson_tkinter_intro.py ├── screen-stat-2a.png ├── screen-stat-2b.png ├── screen-stat-2c.png ├── screen-stat-2d.png ├── screen-stat-2e-en.png ├── screen-stat-2e.png ├── screen-stat-4-en.png ├── screen-stat-4.png ├── screen-stat-5a.png ├── screen-stat-5b.png ├── screen-stat-lesson-buttons-en.png ├── screen-stat-lesson-buttons.png ├── screen-stat-lesson-intro.png ├── statistics.pdf ├── statistics.tex ├── statistics_1.py ├── statistics_2.py ├── statistics_3.py ├── statistics_4.py └── statistics_5.py ├── strings ├── fables.txt ├── frequences.txt ├── strings-unicode.tikz ├── strings.pdf ├── strings.tex ├── strings_1.py ├── strings_2.py ├── strings_3.py ├── strings_4.py ├── strings_5.py └── text_languages.txt ├── turtle ├── coord.tikz ├── fig-turtle-5a.png ├── fig-turtle-5a.tikz ├── fig-turtle-5c.tikz ├── fig-turtle-6c.tikz ├── screen-turtle-0.png ├── screen-turtle-1.png ├── screen-turtle-2a.png ├── screen-turtle-2b.png ├── screen-turtle-2c.png ├── screen-turtle-2d.png ├── screen-turtle-3a.png ├── screen-turtle-3b.png ├── screen-turtle-4a.png ├── screen-turtle-4b.png ├── screen-turtle-4c.png ├── screen-turtle-4d.png ├── screen-turtle-5b.png ├── screen-turtle-6a.png ├── screen-turtle-6b.png ├── turtle.pdf ├── turtle.tex ├── turtle_1.py ├── turtle_2.py ├── turtle_3.py ├── turtle_4.py ├── turtle_5.py ├── turtle_6.py └── turtle_lesson.py └── while ├── conj_un_deux_un.sage ├── fig-while-en.tikz ├── fig-while-lesson.tikz ├── fig-while.tikz ├── while-1.pdf ├── while-1.tex ├── while-2.pdf ├── while-2.tex ├── while_1.py ├── while_2.py ├── while_3.py ├── while_4.py ├── while_5.py ├── while_6.py ├── while_7.py ├── while_lesson_1.py ├── while_lesson_2.py └── while_lesson_timeit.py /.gitignore: -------------------------------------------------------------------------------- 1 | # from WinEdt and GitHub 2 | # ---------------------- 3 | *.aa? 4 | *.acn 5 | *.acr 6 | *.alg 7 | *.aux 8 | *.bak 9 | *.blg 10 | *.dvi 11 | *.fdb_latexmk 12 | *.glg 13 | *.glo 14 | *.gls 15 | *.idx 16 | *.ilg 17 | *.ind 18 | *.ist 19 | *.lof 20 | *.log 21 | *.lot 22 | *.maf 23 | *.mtc 24 | *.mtc0 25 | *.nav 26 | *.nlo 27 | *.out 28 | *.pdfsync 29 | *.pdf_tex 30 | *.prj 31 | *.ps 32 | *.snm 33 | *.synctex* 34 | *.tdo 35 | *.tmp 36 | *.toc 37 | *.vrb 38 | *.xdy 39 | 40 | # le bytecode python 41 | #----------------------- 42 | *.pyc 43 | *.pyo 44 | 45 | # ---------------------- 46 | # plus nécéssaire car un .gitignore par répértoire 47 | # *tikzcach* 48 | 49 | # tous les resultats pdf 50 | # ---------------------- 51 | #*.pdf 52 | 53 | # certains resultats pdf 54 | #----------------------- 55 | # livre-python1-print.pdf 56 | 57 | # Autres 58 | # ---------------------- 59 | *.zip 60 | *.sublime* 61 | *.auxlock 62 | *.ptc 63 | *test*.tex 64 | #vim 65 | *~ 66 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect -------------------------------------------------------------------------------- /binary/binary-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/binary/binary-1.pdf -------------------------------------------------------------------------------- /binary/binary-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/binary/binary-2.pdf -------------------------------------------------------------------------------- /binary/binary_cours.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Binaire - Cours 4 | ############################## 5 | 6 | ############################## 7 | # Cours 2 - 8 | ############################## 9 | 10 | x = 0b11010 11 | print(x) 12 | 13 | y = 0b11111 14 | print(y) 15 | 16 | print(x+y) 17 | 18 | 19 | ############################## 20 | ############################## -------------------------------------------------------------------------------- /binary/fig-binary-1.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=1.2, every node/.style={scale=1.2}] 2 | 3 | 4 | 5 | \draw[very thick] (0,0) -- (1,0); 6 | \draw[very thick] (0,-0.75) -- (0,0); 7 | 8 | \node[blue] at (0.5,0.4) {$123$}; 9 | \node[blue] at (0.5,-1.2) {$4$}; 10 | \node at (0.5,-0.4) {$1234$}; 11 | \node at (-0.5,-0.4) {$10$}; 12 | 13 | \draw[<-,>=latex,ultra thick,blue] (1,0.4) to [bend right] (2,1) node[above right]{quotient}; 14 | \draw[<-,>=latex,ultra thick,blue] (0.4,-1.3) to [bend left] (-2,-1.2) node[above left]{remainder}; 15 | 16 | \end{tikzpicture} -------------------------------------------------------------------------------- /binary/fig-binary-2.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \draw[<-,>=latex,ultra thick,red] (0.5,-2)--(9.5,-2); 4 | 5 | \begin{scope} 6 | \draw[very thick] (0,0) -- (1,0); 7 | \draw[very thick] (0,-0.75) -- (0,0); 8 | 9 | \node at (0.5,0.4) {$7$}; 10 | 11 | \node at (-0.5,-0.4) {$2$}; 12 | \node at (0.5,-0.4) {$14$}; 13 | \node[thick, red, draw, circle] at (0.5,-1.2) {$0$}; 14 | \end{scope} 15 | 16 | \begin{scope}[xshift=3cm] 17 | \draw[thick] (0,0) -- (1,0); 18 | \draw[thick] (0,-0.75) -- (0,0); 19 | 20 | \node at (0.5,0.4) {$3$}; 21 | 22 | \node at (-0.5,-0.4) {$2$}; 23 | \node at (0.5,-0.4) {$7$}; 24 | \node[thick, red, draw, circle] at (0.5,-1.2) {$1$}; 25 | \end{scope} 26 | 27 | 28 | \begin{scope}[xshift=6cm] 29 | \draw[thick] (0,0) -- (1,0); 30 | \draw[thick] (0,-0.75) -- (0,0); 31 | 32 | \node at (0.5,0.4) {$1$}; 33 | 34 | \node at (-0.5,-0.4) {$2$}; 35 | \node at (0.5,-0.4) {$3$}; 36 | \node[thick, red, draw, circle] at (0.5,-1.2) {$1$}; 37 | \end{scope} 38 | 39 | 40 | \begin{scope}[xshift=9cm] 41 | \draw[thick] (0,0) -- (1,0); 42 | \draw[thick] (0,-0.75) -- (0,0); 43 | 44 | \node at (0.5,0.4) {$0$}; 45 | 46 | \node at (-0.5,-0.4) {$2$}; 47 | \node at (0.5,-0.4) {$1$}; 48 | \node[thick, red, draw, circle] at (0.5,-1.2) {$1$}; 49 | \end{scope} 50 | 51 | 52 | 53 | \end{tikzpicture} -------------------------------------------------------------------------------- /binary/fig-binary-3.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | %\draw[<-,>=latex,ultra thick,red] (-0.5,-1.75)--(8.5,-1.75); 4 | 5 | \begin{scope} 6 | \draw[thick] (0,0) -- (1,0); 7 | \draw[thick] (0,-0.75) -- (0,0); 8 | 9 | \node at (0.5,0.4) {$25$}; 10 | 11 | \node at (-0.5,-0.4) {$2$}; 12 | \node at (0.5,-0.4) {$50$}; 13 | \node[thick, red, draw, circle] at (0.5,-1.2) {$0$}; 14 | \end{scope} 15 | 16 | \begin{scope}[xshift=2.5cm] 17 | \draw[thick] (0,0) -- (1,0); 18 | \draw[thick] (0,-0.75) -- (0,0); 19 | 20 | \node at (0.5,0.4) {$12$}; 21 | 22 | \node at (-0.5,-0.4) {$2$}; 23 | \node at (0.5,-0.4) {$25$}; 24 | \node[thick, red, draw, circle] at (0.5,-1.2) {$1$}; 25 | \end{scope} 26 | 27 | 28 | \begin{scope}[xshift=5cm] 29 | \draw[thick] (0,0) -- (1,0); 30 | \draw[thick] (0,-0.75) -- (0,0); 31 | 32 | \node at (0.5,0.4) {$6$}; 33 | 34 | \node at (-0.5,-0.4) {$2$}; 35 | \node at (0.5,-0.4) {$12$}; 36 | \node[thick, red, draw, circle] at (0.5,-1.2) {$0$}; 37 | \end{scope} 38 | 39 | 40 | \begin{scope}[xshift=7.5cm] 41 | \draw[thick] (0,0) -- (1,0); 42 | \draw[thick] (0,-0.75) -- (0,0); 43 | 44 | \node at (0.5,0.4) {$3$}; 45 | 46 | \node at (-0.5,-0.4) {$2$}; 47 | \node at (0.5,-0.4) {$6$}; 48 | \node[thick, red, draw, circle] at (0.5,-1.2) {$0$}; 49 | \end{scope} 50 | 51 | \begin{scope}[xshift=10cm] 52 | \draw[thick] (0,0) -- (1,0); 53 | \draw[thick] (0,-0.75) -- (0,0); 54 | 55 | \node at (0.5,0.4) {$1$}; 56 | 57 | \node at (-0.5,-0.4) {$2$}; 58 | \node at (0.5,-0.4) {$3$}; 59 | \node[thick, red, draw, circle] at (0.5,-1.2) {$1$}; 60 | \end{scope} 61 | 62 | \begin{scope}[xshift=12.5cm] 63 | \draw[thick] (0,0) -- (1,0); 64 | \draw[thick] (0,-0.75) -- (0,0); 65 | 66 | \node at (0.5,0.4) {$0$}; 67 | 68 | \node at (-0.5,-0.4) {$2$}; 69 | \node at (0.5,-0.4) {$1$}; 70 | \node[thick, red, draw, circle] at (0.5,-1.2) {$1$}; 71 | \end{scope} 72 | 73 | \end{tikzpicture} -------------------------------------------------------------------------------- /binary/fig-binary-4.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \Large 4 | 5 | \begin{scope} 6 | \node[left] at (0,2.6) {$1.0.1.1.0$}; 7 | \node[left] at (0,2) {$1.1.0.1.0$}; 8 | \node[left] at (0,1) {$1.0.0.1.0$}; 9 | \node[left] at (-3,2) {AND}; 10 | \draw[thick] (-4,1.5)--(0,1.5); 11 | \end{scope} 12 | 13 | \begin{scope}[xshift=7cm] 14 | \node[left] at (0,2.6) {$1.0.0.1.0$}; 15 | \node[left] at (0,2) {{\color{black!40}$0.0.$}$1.1.0$}; 16 | \node[left] at (0,1) {$1.0.1.1.0$}; 17 | \node[left] at (-3,2) {OR}; 18 | \draw[thick] (-4,1.5)--(0,1.5); 19 | \end{scope} 20 | 21 | \end{tikzpicture} -------------------------------------------------------------------------------- /bitcoin/bitcoin.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/bitcoin/bitcoin.pdf -------------------------------------------------------------------------------- /bitcoin/bitcoin_lesson_time.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Bitcoin 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Cours - Chromètre 9 | ############################## 10 | 11 | import time 12 | 13 | debut_chrono = time.time() 14 | print(debut_chrono) 15 | 16 | time.sleep(2) 17 | 18 | fin_chrono = time.time() 19 | total_chrono = fin_chrono - debut_chrono 20 | print("Temps d'execution (en secondes) :",total_chrono) 21 | -------------------------------------------------------------------------------- /bitcoin/fig-bitcoin-1.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}%[scale=1.2, every node/.style={scale=1.2}] 2 | %\usetikzlibrary{backgrounds} 3 | \def\rectangle{ 4 | \draw[thick] (0,0) rectangle +(6,1.5); 5 | \foreach \i in {1,2,3,4,5}{ 6 | \draw[thick] (\i,0) -- ++(0,1.5); 7 | }; 8 | } 9 | 10 | \foreach \j in {0,3,6,9,12}{ 11 | \begin{scope}[yshift=\j cm] 12 | \rectangle; 13 | \end{scope} 14 | } 15 | 16 | \foreach \i in {0,1,2,3,4,5}{ 17 | \node at (\i+0.5,12.75) {$b_\i$}; 18 | }; 19 | 20 | % Modulo 100 21 | \foreach \i in {0,1,2,3,4,5}{ 22 | \draw[<-,>=latex,ultra thick,red] (\i+0.5,1.75) -- ++(0,1); 23 | }; 24 | 25 | % Permutation 26 | % \begin{scope}[on background layer] 27 | \draw[<-,>=latex,ultra thick,red!60] (0.5,4.75) -- ++(5,1); 28 | % \end{scope} 29 | \foreach \i in {1,2,3,4,5}{ 30 | \draw[<-,>=latex,ultra thick,red] (\i+0.5,4.75) -- ++(-1,1); 31 | }; 32 | 33 | % Multiplications 34 | \foreach \i/\p in {0/7,2/13,4/19}{ 35 | \draw[<-,>=latex,ultra thick,red] (\i+0.35,7.75) -- ++(0,1) node[midway,right,scale=0.45,black]{$\times \p + 1$}; 36 | }; 37 | \foreach \i/\p in {1/11,3/17,5/23}{ 38 | \draw[<-,>=latex,ultra thick,red] (\i+0.35,7.75) -- ++(0,1) node[pos=0.7,right,scale=0.45,black]{$\times \p + 1$}; 39 | }; 40 | 41 | % Additions 42 | \foreach \i in {0,2,4}{ 43 | \draw[<-,>=latex,ultra thick,red] (\i+0.35,10.75) -- ++(0,1); 44 | }; 45 | \foreach \i in {1,3,5}{ 46 | \draw[<-,>=latex,ultra thick,red] (\i+0.5,10.75) -- ++(0,1); 47 | \draw[ultra thick,red] (\i+0.5,11.25) -- ++(-0.75,0.5) node[pos=0.3,above,black] {$+$}; 48 | }; 49 | 50 | \node[right,red] at (6.5,2.25) {\bf (d) modulo 100}; 51 | \node[right,red] at (6.5,5.25) {\bf (c) circular permutation}; 52 | \node[right,red] at (6.5,8.25) {\bf (b) multiplications}; 53 | \node[right,red] at (6.5,11.25) {\bf (a) additions}; 54 | 55 | \end{tikzpicture} -------------------------------------------------------------------------------- /blocks/blocks.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/blocks.pdf -------------------------------------------------------------------------------- /blocks/fig-blocks-1.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | \fill[green!70!black] (4,3) rectangle ++(1,1); 5 | \fill[green!70!black] (2,0) rectangle ++(1,1); 6 | \fill[green!70!black] (2,1) rectangle ++(1,1); 7 | \fill[green!70!black] (2,2) rectangle ++(1,1); 8 | \fill[green!70!black] (3,0) rectangle ++(1,1); 9 | 10 | \draw[thick] (0,0) grid ++(6,4); 11 | 12 | \node at (3,-0.7) {\bf An array with $5$ blocks ($n=4$, $p=6$)}; 13 | 14 | 15 | \draw[->,>=latex,very thick] (0,5) to node[midway, above] {index $j$} ++(6,0) ; 16 | \draw[->,>=latex,very thick] (-1.5,4) to node[midway, left] {index $i$} ++(0,-4) ; 17 | 18 | \node[scale=0.7,above] at (0.5,4) {$j=0$}; 19 | \node[scale=0.7,above] at (1.5,4) {$j=1$}; 20 | \node[scale=0.7,above] at (2.5,4) {$j=2$}; 21 | \node[scale=0.7,above] at (3.5,4) {$j=3$}; 22 | \node[scale=0.7,above] at (4.5,4) {$j=4$}; 23 | \node[scale=0.7,above] at (5.5,4) {$j=5$}; 24 | 25 | \node[scale=0.7,left] at (0,3.5) {$i=0$}; 26 | \node[scale=0.7,left] at (0,2.5) {$i=1$}; 27 | \node[scale=0.7,left] at (0,1.5) {$i=2$}; 28 | \node[scale=0.7,left] at (0,0.5) {$i=3$}; 29 | 30 | 31 | \end{tikzpicture} -------------------------------------------------------------------------------- /blocks/fig-blocks-2.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | %\fill[green!70!black] (3,2) rectangle ++(1,1); 5 | \fill[green!70!black] (2,0) rectangle ++(1,1); 6 | \fill[green!70!black] (2,1) rectangle ++(1,1); 7 | \fill[green!70!black] (2,2) rectangle ++(1,1); 8 | \fill[green!70!black] (3,0) rectangle ++(1,1); 9 | 10 | \draw[thick] (0,0) grid ++(6,4); 11 | 12 | \node at (3,-0.7) {\bf Before}; 13 | 14 | 15 | \node[scale=0.7,above] at (0.5,4) {$0$}; 16 | \node[scale=0.7,above] at (1.5,4) {$1$}; 17 | \node[scale=0.7,above] at (2.5,4) {$2$}; 18 | \node[scale=0.7,above] at (3.5,4) {$3$}; 19 | \node[scale=0.7,above] at (4.5,4) {$4$}; 20 | \node[scale=0.7,above] at (5.5,4) {$5$}; 21 | 22 | 23 | \begin{scope}[xshift=8cm] 24 | \fill[green!70!black] (3,2) rectangle ++(1,1); 25 | \fill[green!70!black] (2,0) rectangle ++(1,1); 26 | \fill[green!70!black] (2,1) rectangle ++(1,1); 27 | \fill[green!70!black] (2,2) rectangle ++(1,1); 28 | \fill[green!70!black] (3,0) rectangle ++(1,1); 29 | 30 | \draw[thick] (0,0) grid ++(6,4); 31 | 32 | \node at (3,-0.7) {\bf After}; 33 | 34 | 35 | \node[scale=0.7,above] at (0.5,4) {$0$}; 36 | \node[scale=0.7,above] at (1.5,4) {$1$}; 37 | \node[scale=0.7,above] at (2.5,4) {$2$}; 38 | \node[scale=0.7,above] at (3.5,4) {$3$}; 39 | \node[scale=0.7,above] at (4.5,4) {$4$}; 40 | \node[scale=0.7,above] at (5.5,4) {$5$}; 41 | \end{scope} 42 | 43 | 44 | \end{tikzpicture} -------------------------------------------------------------------------------- /blocks/fig-blocks-3.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \fill[green!70!black] (1,2) rectangle ++(1,1); 4 | \fill[green!70!black] (3,2) rectangle ++(1,1); 5 | \fill[green!70!black] (3,3) rectangle ++(1,1); 6 | \fill[green!70!black] (4,3) rectangle ++(1,1); 7 | \fill[green!70!black] (2,0) rectangle ++(1,1); 8 | \fill[green!70!black] (2,1) rectangle ++(1,1); 9 | \fill[green!70!black] (2,2) rectangle ++(1,1); 10 | \fill[green!70!black] (3,0) rectangle ++(1,1); 11 | \fill[green!70!black] (5,0) rectangle ++(1,1); 12 | \fill[green!70!black] (5,1) rectangle ++(1,1); 13 | 14 | \draw[thick] (0,0) grid ++(6,4); 15 | 16 | \node at (3,-0.7) {\bf Throw of $10$ blocks}; 17 | 18 | 19 | 20 | 21 | \end{tikzpicture} -------------------------------------------------------------------------------- /blocks/screen-blocks-bloc0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-bloc0.png -------------------------------------------------------------------------------- /blocks/screen-blocks-bloc00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-bloc00.png -------------------------------------------------------------------------------- /blocks/screen-blocks-bloc1-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-bloc1-en.png -------------------------------------------------------------------------------- /blocks/screen-blocks-bloc1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-bloc1.png -------------------------------------------------------------------------------- /blocks/screen-blocks-bloc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-bloc2.png -------------------------------------------------------------------------------- /blocks/screen-blocks-lesson-move-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-lesson-move-en.png -------------------------------------------------------------------------------- /blocks/screen-blocks-lesson-move.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-lesson-move.png -------------------------------------------------------------------------------- /blocks/screen-blocks-tree00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-tree00.png -------------------------------------------------------------------------------- /blocks/screen-blocks-tree1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-tree1.png -------------------------------------------------------------------------------- /blocks/screen-blocks-tree2-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-tree2-en.png -------------------------------------------------------------------------------- /blocks/screen-blocks-tree2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/blocks/screen-blocks-tree2.png -------------------------------------------------------------------------------- /blocks/tkinter_move.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Tkinter - Moves 4 | ############################## 5 | 6 | from tkinter import * 7 | 8 | the_width = 400 9 | the_height = 200 10 | 11 | root = Tk() 12 | canvas = Canvas(root, width=the_width, height=the_height, background="white") 13 | canvas.pack(fill="both", expand=True) 14 | 15 | # Coordinates and speed 16 | x0, y0 = 100,100 17 | dx = +5 # Horizontal speed 18 | dy = +2 # Vertical speed 19 | 20 | # The rectangle to move 21 | rect = canvas.create_rectangle(x0,y0,x0+20,y0+20,width=2,fill="red") 22 | 23 | # Main function 24 | def mymove(): 25 | global x0, y0, dx, dy 26 | 27 | x0 = x0 + dx # New abscissa 28 | y0 = y0 + dy # New ordinate 29 | 30 | canvas.coords(rect,x0,y0,x0+20,y0+20) # Move 31 | 32 | if x0 < 0 or x0 > the_width: 33 | dx = -dx # Change of horizontal direction 34 | if y0 < 0 or y0 > the_height: 35 | dy = -dy # Change of vertical direction 36 | 37 | canvas.after(50,mymove) # Call after 50 milliseconds 38 | 39 | return 40 | 41 | # Function for the button 42 | def action_move(): 43 | mymove() 44 | return 45 | 46 | # Buttons 47 | button_move = Button(root,text="Move", width=20, command=action_move) 48 | button_move.pack(pady=10) 49 | 50 | button_quit = Button(root,text="Quit", width=20, command=root.quit) 51 | button_quit.pack(side=BOTTOM, pady=10) 52 | 53 | root.mainloop() 54 | 55 | -------------------------------------------------------------------------------- /book-python1-print.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/book-python1-print.pdf -------------------------------------------------------------------------------- /book-python1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/book-python1.pdf -------------------------------------------------------------------------------- /code/code.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/code/code.pdf -------------------------------------------------------------------------------- /cover/cover.txt: -------------------------------------------------------------------------------- 1 | # Instructions pour la couverture 2 | 3 | # couleur violet : d01a55 4 | # couleur vert : c1d208 5 | # couleur gris : 666666 (gris 60%) 6 | 7 | # fonte : Roboto Condensed bold 8 | 9 | Livre Pyhton 1 - en 10 | 266 pages 11 | 12 | Size 7.5 x 9.25 in 13 | Template cover : 403 x 241 mm -------------------------------------------------------------------------------- /cover/cover_old/AlteDin1451Mittelschrift.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/cover_old/AlteDin1451Mittelschrift.ttf -------------------------------------------------------------------------------- /cover/cover_old/exo7_logo_couleurs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/cover_old/exo7_logo_couleurs.pdf -------------------------------------------------------------------------------- /cover/cover_old/exo7_logo_couleurs.tex: -------------------------------------------------------------------------------- 1 | \documentclass[tikz,border=7pt]{standalone} 2 | \usetikzlibrary{svg.path} 3 | 4 | \definecolor{myred}{rgb}{0.93,0.26,0} 5 | \definecolor{myorange}{rgb}{0.97,0.58,0} 6 | \definecolor{myyellow}{rgb}{1,0.86,0} 7 | 8 | \begin{document} 9 | \begin{tikzpicture}[yscale=-1,x=1pt,y=1pt] 10 | \fill[color=myorange] svg{M30 70l40 0 0 40-40 0z}; 11 | \fill[color=myred] svg{M30 70l0-30-30 0 0 30z}; 12 | \fill[color=myyellow] svg{M70 70l-40-30 30-40 40 30-30 40z}; 13 | \fill[color=black] svg{M49.49 35.64l4.61 0c.55 0 .84-.13 .85-.83 0-.65-.23-.83-.85-.82l-4.61 0 0-3.26 .86 0c1.37 0 2.76 .06 4.12 .06 .62 0 1.02 0 1.02-.84l0-.15c0-.56-.12-.84-.84-.84l-6.91 0c-.63 0-.84 .19-.84 .84l0 10.46c0 .63 .19 .84 .84 .84l7.18 0c.67 0 .84-.23 .84-.84l0-.25c0-.84-.4-.84-.99-.84-.91 0-1.81 .04-2.72 .04-.44 0-2.25 .02-2.56 .03zM61.87 36.93l2.55-3.12c.18-.21 .18-.28 .18-.37 0-.38-.35-.38-.62-.39l-.76 0c-.31 0-.53 0-.77 .27-.09 .09-1.23 1.62-1.53 2.02l-1.51-1.9c-.3-.37-.49-.38-.9-.39l-.77 0c-.23 0-.61 0-.61 .39 0 .12 .05 .19 .17 .33l2.65 3.16-2.77 3.43c-.11 .12-.17 .21-.18 .36 0 .38 .38 .38 .63 .38l.76 0c.59 0 .62-.06 1-.63l1.51-2.25 1.79 2.53c.25 .35 .46 .35 .83 .35l.78 0c.24 0 .61 0 .61-.38 0-.14-.07-.21-.19-.37zM74.47 37.15c0-2.88-1.4-4.39-4.27-4.4-2.94 0-4.29 1.56-4.29 4.4 0 2.86 1.51 4.15 4.27 4.14 2.76 0 4.28-1.26 4.29-4.14zm-4.27 2.77c-1.9 0-1.9-1.58-1.9-2.99 0-1.35 0-2.92 1.88-2.91 1.9 0 1.9 1.55 1.9 2.91 0 1.39 0 2.99-1.88 2.99zM81.48 30.79c-3.94 4.34-3.94 8.76-3.93 9.66 0 .56 .12 .84 .84 .84l.81 0c.28 0 .84 0 .84-.68 .05-4.36 1.58-7.54 3.69-10.19 .14-.18 .14-.32 .14-.64 0-.38 0-.86-.74-.87-.6-.02-4.13-.02-4.99-.02l-1.11 0c-.84 0-1.19 0-1.19 .84l0 .23c0 .28 0 .61 .37 .77 .12 .07 .7 .07 1.07 .07 .4 0 .83-.02 1.23-.01z}; 14 | \end{tikzpicture} 15 | \end{document} 16 | -------------------------------------------------------------------------------- /cover/cover_old/exo7_logo_white.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/cover_old/exo7_logo_white.pdf -------------------------------------------------------------------------------- /cover/cover_old/exo7_logo_white.tex: -------------------------------------------------------------------------------- 1 | \documentclass[tikz,border=7pt]{standalone} 2 | \usetikzlibrary{svg.path} 3 | 4 | \begin{document} 5 | \begin{tikzpicture}[yscale=-1,x=1pt,y=1pt,white] 6 | \fill svg{M30 70l40 0 0 40-40 0z}; 7 | \fill svg{M30 70l0-30-30 0 0 30z}; 8 | \fill svg{M70 70l-40-30 30-40 40 30-30 40zM49.49 35.64l4.61 0c.55 0 .84-.13 .85-.83 0-.65-.23-.83-.85-.82l-4.61 0 0-3.26 .86 0c1.37 0 2.76 .06 4.12 .06 .62 0 1.02 0 1.02-.84l0-.15c0-.56-.12-.84-.84-.84l-6.91 0c-.63 0-.84 .19-.84 .84l0 10.46c0 .63 .19 .84 .84 .84l7.18 0c.67 0 .84-.23 .84-.84l0-.25c0-.84-.4-.84-.99-.84-.91 0-1.81 .04-2.72 .04-.44 0-2.25 .02-2.56 .03zM61.87 36.93l2.55-3.12c.18-.21 .18-.28 .18-.37 0-.38-.35-.38-.62-.39l-.76 0c-.31 0-.53 0-.77 .27-.09 .09-1.23 1.62-1.53 2.02l-1.51-1.9c-.3-.37-.49-.38-.9-.39l-.77 0c-.23 0-.61 0-.61 .39 0 .12 .05 .19 .17 .33l2.65 3.16-2.77 3.43c-.11 .12-.17 .21-.18 .36 0 .38 .38 .38 .63 .38l.76 0c.59 0 .62-.06 1-.63l1.51-2.25 1.79 2.53c.25 .35 .46 .35 .83 .35l.78 0c.24 0 .61 0 .61-.38 0-.14-.07-.21-.19-.37zM74.47 37.15c0-2.88-1.4-4.39-4.27-4.4-2.94 0-4.29 1.56-4.29 4.4 0 2.86 1.51 4.15 4.27 4.14 2.76 0 4.28-1.26 4.29-4.14zm-4.27 2.77c-1.9 0-1.9-1.58-1.9-2.99 0-1.35 0-2.92 1.88-2.91 1.9 0 1.9 1.55 1.9 2.91 0 1.39 0 2.99-1.88 2.99zM81.48 30.79c-3.94 4.34-3.94 8.76-3.93 9.66 0 .56 .12 .84 .84 .84l.81 0c.28 0 .84 0 .84-.68 .05-4.36 1.58-7.54 3.69-10.19 .14-.18 .14-.32 .14-.64 0-.38 0-.86-.74-.87-.6-.02-4.13-.02-4.99-.02l-1.11 0c-.84 0-1.19 0-1.19 .84l0 .23c0 .28 0 .61 .37 .77 .12 .07 .7 .07 1.07 .07 .4 0 .83-.02 1.23-.01z}; 9 | \end{tikzpicture} 10 | \end{document} 11 | -------------------------------------------------------------------------------- /cover/cover_old/logo-python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/cover_old/logo-python.png -------------------------------------------------------------------------------- /cover/cover_old/python-logo-en.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/cover_old/python-logo-en.pdf -------------------------------------------------------------------------------- /cover/cover_old/python-logo-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/cover_old/python-logo-en.png -------------------------------------------------------------------------------- /cover/cover_old/python-logo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/cover_old/python-logo.pdf -------------------------------------------------------------------------------- /cover/cover_old/python_cover_en1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/cover_old/python_cover_en1.pdf -------------------------------------------------------------------------------- /cover/cover_old/serpent.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | \definecolor{serpent}{HTML}{011A27} 3 | \definecolor{oeilserpent}{HTML}{AAAAAA} 4 | 5 | % \path[ultra thick,fill =serpent] (0,0) arc (90:-90:-1) -- ++(9,0) -- ++(0,-6 ) -- ++ (-4,0) -- ++(0,-3) -- ++(4,0) -- ++(0,-6) -- ++(-8,0) % -- ++ (-1,1) -- ++ (1,1) 6 | % --++(0,2) 7 | % -- ++(6,0) -- ++(0,2) --++(-4,0) -- ++(0,7) --++(4,0) -- ++(0,2) --cycle ; 8 | 9 | \path[fill=oeilserpent] (0,1.2) circle (0.3); 10 | 11 | \draw[ultra thick] (0,0) arc (90:-90:-1) -- ++(9,0) -- ++(0,-6 ) -- ++ (-4,0) -- ++(0,-3) -- ++(8,0) -- ++(0,-2) --++(-10,0)--++(0,7) --++(4,0) --++(0,2) --cycle ; 12 | \end{tikzpicture} -------------------------------------------------------------------------------- /cover/python-logo-en-exo7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/python-logo-en-exo7.png -------------------------------------------------------------------------------- /cover/python-logo-exo7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/python-logo-exo7.png -------------------------------------------------------------------------------- /cover/python-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/python-logo.png -------------------------------------------------------------------------------- /cover/python1-en-cover-kdp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/cover/python1-en-cover-kdp.pdf -------------------------------------------------------------------------------- /files/averages.txt: -------------------------------------------------------------------------------- 1 | Tintin Vador 13.00 2 | Bill Croft 13.33 3 | Hermione Skywalker 12.33 4 | Lara Parker 13.33 5 | Hermione Croft 13.17 6 | Robin Vador 9.00 7 | -------------------------------------------------------------------------------- /files/cities_lat_long.txt: -------------------------------------------------------------------------------- 1 | Paris 48.853 2.350 2 | New-York 40.713 -74.006 3 | Vancouver 49.250 -123.119 4 | Lima -12.043 -77.0282 5 | Hong-Kong 22.286 114.158 6 | Addis-Abeba 9.0250 38.747 7 | -------------------------------------------------------------------------------- /files/cities_lat_long_distances.txt: -------------------------------------------------------------------------------- 1 | Paris New-York Vancouver Lima Hong-Kong Addis-Abeba 2 | Paris 0 5837 7924 10253 9629 5573 3 | New-York 5837 0 3905 5874 12959 11207 4 | Vancouver 7924 3905 0 8168 10257 13298 5 | Lima 10253 5874 8168 0 18371 13001 6 | Hong-Kong 9629 12959 10257 18371 0 8135 7 | Addis-Abeba 5573 11207 13298 13001 8135 0 8 | -------------------------------------------------------------------------------- /files/cities_xy.txt: -------------------------------------------------------------------------------- 1 | Paris 500 800 2 | Lille 500 1000 3 | Nantes 100 700 4 | Marseille 900 0 -------------------------------------------------------------------------------- /files/cities_xy_distances.txt: -------------------------------------------------------------------------------- 1 | Paris Lille Nantes Marseille 2 | Paris 0 200 412 894 3 | Lille 200 0 500 1077 4 | Nantes 412 500 0 1063 5 | Marseille 894 1077 1063 0 6 | -------------------------------------------------------------------------------- /files/fig-france.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \tikzstyle{edge} = [draw, thick] 4 | \tikzstyle{vertex} = [draw] 5 | 6 | \draw (0,0) grid (11,11); 7 | 8 | \coordinate (L) at (5,10); 9 | \coordinate (P) at (5,8); 10 | \coordinate (S) at (10,8); 11 | \coordinate (Ly) at (9,4); 12 | \coordinate (M) at (9,0); 13 | \coordinate (T) at (4,1); 14 | \coordinate (N) at (1,7); 15 | \coordinate (B) at (1,2); 16 | 17 | \foreach \V/\Ville/\pos in {L/Lille/above,P/Paris/below,S/Strasbourg/right,Ly/Lyon/right,M/Marseille/below,T/Toulouse/below,N/Nantes/left, B/Bordeaux/left}{ 18 | \fill[blue] (\V) circle(0.1); 19 | \node[\pos,blue] at (\V) {\Ville}; 20 | } 21 | 22 | \fill (0,0) circle (0.1) node[below left] at (0,0) {$(0,0)$}; 23 | 24 | \draw[<->,>=latex,thick] (1,-0.4)--++(1,0) node[midway,below]{100 km}; 25 | 26 | 27 | 28 | \draw[edge] (0,0) -- (1,4) -- (0,8)--(-2,9) -- (5,12) -- (11,8)--(10,-1)--cycle; 29 | 30 | % \draw[edge] (L)--(P) node[midway,right]{200}; 31 | % \draw[edge] (L)--(N) node[midway,above left]{500}; 32 | % \draw[edge] (P)--(N) node[midway,below]{400}; 33 | % \draw[edge] (P)--(S) node[midway,above]{500}; 34 | % \draw[edge] (P)--(Ly) node[midway,right]{500}; 35 | % \draw[edge] (Ly)--(M) node[midway,right]{300}; 36 | % \draw[edge] (T)--(M) node[midway,above]{400}; 37 | % \draw[edge] (T)--(B) node[midway,above]{200}; 38 | % \draw[edge] (N)--(B) node[midway,left]{400}; 39 | % \draw[edge] (S)--(Ly) node[midway,right]{400}; 40 | % \draw[edge] (S)--(L) node[midway,above right]{400}; 41 | 42 | 43 | \end{tikzpicture} -------------------------------------------------------------------------------- /files/files.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/files.pdf -------------------------------------------------------------------------------- /files/files_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Files 4 | ############################## 5 | 6 | from random import * 7 | 8 | 9 | ############################## 10 | # Activity 1 - Write to a file 11 | ############################## 12 | 13 | ## Question 1 ## 14 | 15 | def write_file_grades(): 16 | 17 | # Creation of a file to write 18 | filename = "grades.txt" 19 | fi = open(filename,"w") 20 | 21 | # Lists names 22 | list_firstnames = ["Lara","Robin","Hermione","Bill","Alice","James","Tintin"] 23 | list_names = ["Skywalker","Croft","Voldemort","Vador","Bond","Parker"] 24 | 25 | for i in range(6): 26 | firstname = choice(list_firstnames) 27 | name = choice(list_names) 28 | grade = str(randint(10,40)/2) + " " + str(randint(10,40)/2) + " " + str(randint(10,40)/2) 29 | line = firstname + " " + name + " " + grade + "\n" 30 | 31 | # Write line 32 | fi.write(line) 33 | 34 | # Close file 35 | fi.close() 36 | 37 | return 38 | 39 | # Test 40 | 41 | print("--- File 'grades.txt' ---") 42 | write_file_grades() 43 | 44 | 45 | ## Question 2 ## 46 | 47 | def write_file_averages(): 48 | 49 | # File to read 50 | file_grades = "grades.txt" 51 | fi_in = open(file_grades,"r") 52 | 53 | # File to write 54 | file_averages = "averages.txt" 55 | fi_out = open(file_averages,"w") 56 | 57 | for line in fi_in: 58 | mylist = line.split() 59 | average = (float(mylist[2])+float(mylist[3])+float(mylist[4]))/3 60 | average_str = '{0:.2f}'.format(average) 61 | new_line = mylist[0] + " " + mylist[1] + " " + average_str + "\n" 62 | fi_out.write(new_line) 63 | 64 | # Fermeture des fichiers 65 | fi_in.close() 66 | fi_out.close() 67 | return 68 | 69 | print("--- File 'averages.txt' ---") 70 | write_file_averages() 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /files/files_2.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Files 4 | ############################## 5 | 6 | from random import * 7 | import matplotlib.pyplot as plt 8 | 9 | ############################## 10 | # Activity 2 - 11 | ############################## 12 | 13 | ## Question 1 ## 14 | 15 | def write_file_sales(): 16 | 17 | # Create a file to write 18 | filename = "sales.csv" 19 | fi = open(filename,"w") 20 | 21 | # List of products nom 22 | list_products = ["Mountain bike","Surfboard","Running shoes","Badminton racket","Volley ball"] 23 | 24 | # Top lines 25 | fi.write("Best sales of the brand 'Pentathlon'\n\n") 26 | fi.write(",2015,2016,2017,2018,2019,2020\n\n") 27 | 28 | for product in list_products: 29 | 30 | # Generate random sales 31 | sales = "" 32 | for i in range(6): 33 | sales = sales + "," + str(randint(50,100)*10) 34 | 35 | line = product + sales + "\n" 36 | 37 | # Write 38 | fi.write(line) 39 | 40 | # Close file 41 | fi.close() 42 | 43 | return 44 | 45 | print("--- Files 'sales.csv' ---") 46 | write_file_sales() 47 | 48 | 49 | ## Question 2 ## 50 | 51 | def display_sales(): 52 | 53 | # File to read 54 | file_sales = "sales.csv" 55 | fi_in = open(file_sales,"r") 56 | 57 | num_line = 0 58 | for line in fi_in: 59 | if num_line > 3: # we forget the top lines 60 | mylist = line.split(",") 61 | data = [float(x) for x in mylist[1:]] 62 | plt.plot(data) 63 | 64 | num_line += 1 65 | 66 | # Close file 67 | fi_in.close() 68 | 69 | # Display 70 | plt.grid() 71 | plt.show() 72 | 73 | return 74 | 75 | print("--- Display 'sales.csv' ---") 76 | display_sales() 77 | 78 | -------------------------------------------------------------------------------- /files/files_lesson.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Files 4 | ############################## 5 | 6 | ############################## 7 | # Write in a file 8 | ############################## 9 | 10 | # Creation of a file to write 11 | fi = open("my_file.txt","w") 12 | 13 | # Write first line 14 | fi.write("Hello world!\n") 15 | 16 | # Write second line 17 | line = "Hi there.\n" 18 | fi.write(line) 19 | 20 | fi.close() 21 | 22 | ############################## 23 | # Read lines from a file 24 | ############################## 25 | 26 | fi = open("my_file.txt","r") 27 | 28 | for line in fi: 29 | print(line) 30 | 31 | fi.close() -------------------------------------------------------------------------------- /files/grades.txt: -------------------------------------------------------------------------------- 1 | Tintin Vador 15.0 5.0 19.0 2 | Bill Croft 15.0 14.5 10.5 3 | Hermione Skywalker 10.5 7.0 19.5 4 | Lara Parker 12.5 13.0 14.5 5 | Hermione Croft 11.5 18.5 9.5 6 | Robin Vador 8.0 8.0 11.0 7 | -------------------------------------------------------------------------------- /files/lesson-image_bw.pbm: -------------------------------------------------------------------------------- 1 | P1 2 | 4 5 3 | 1 1 1 1 4 | 1 0 0 0 5 | 1 1 1 0 6 | 1 0 0 0 7 | 1 1 1 1 8 | 9 | 10 | -------------------------------------------------------------------------------- /files/lesson-image_col.ppm: -------------------------------------------------------------------------------- 1 | P3 2 | 3 2 3 | 255 4 | 255 0 0 0 255 0 0 0 255 5 | 0 128 255 255 128 0 128 255 0 6 | -------------------------------------------------------------------------------- /files/lesson-image_gray.pgm: -------------------------------------------------------------------------------- 1 | P2 2 | 4 5 3 | 255 4 | 0 0 0 0 5 | 192 192 192 192 6 | 192 255 128 128 7 | 192 255 64 64 8 | 192 0 0 0 -------------------------------------------------------------------------------- /files/my_file.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello world! 4 | Hi there. 5 | -------------------------------------------------------------------------------- /files/sales.csv: -------------------------------------------------------------------------------- 1 | Best sales of the brand 'Pentathlon' 2 | 3 | ,2015,2016,2017,2018,2019,2020 4 | 5 | Mountain bike,560,890,500,550,650,970 6 | Surfboard,550,690,750,640,710,790 7 | Running shoes,850,740,790,1000,680,540 8 | Badminton racket,710,640,620,550,790,880 9 | Volley ball,900,550,790,510,930,800 10 | -------------------------------------------------------------------------------- /files/screen-files-1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-1a.png -------------------------------------------------------------------------------- /files/screen-files-1b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-1b.png -------------------------------------------------------------------------------- /files/screen-files-2a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-2a.png -------------------------------------------------------------------------------- /files/screen-files-2b-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-2b-en.png -------------------------------------------------------------------------------- /files/screen-files-2b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-2b.png -------------------------------------------------------------------------------- /files/screen-files-2c-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-2c-en.png -------------------------------------------------------------------------------- /files/screen-files-2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-2c.png -------------------------------------------------------------------------------- /files/screen-files-4a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-4a.png -------------------------------------------------------------------------------- /files/screen-files-4b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-4b.png -------------------------------------------------------------------------------- /files/screen-files-4c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-4c.png -------------------------------------------------------------------------------- /files/screen-files-4d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-4d.png -------------------------------------------------------------------------------- /files/screen-files-lesson-1-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-lesson-1-en.png -------------------------------------------------------------------------------- /files/screen-files-lesson-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-files-lesson-1.png -------------------------------------------------------------------------------- /files/screen-image_coul.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-image_coul.png -------------------------------------------------------------------------------- /files/screen-image_coul_gris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-image_coul_gris.png -------------------------------------------------------------------------------- /files/screen-image_gris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-image_gris.png -------------------------------------------------------------------------------- /files/screen-image_nb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-image_nb.png -------------------------------------------------------------------------------- /files/screen-lesson-image_coul.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-lesson-image_coul.png -------------------------------------------------------------------------------- /files/screen-lesson-image_gris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-lesson-image_gris.png -------------------------------------------------------------------------------- /files/screen-lesson-image_nb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-lesson-image_nb.png -------------------------------------------------------------------------------- /files/screen-simple_nb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-simple_nb.png -------------------------------------------------------------------------------- /files/screen-simple_nb_inverse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/files/screen-simple_nb_inverse.png -------------------------------------------------------------------------------- /find/find.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/find/find.pdf -------------------------------------------------------------------------------- /find/find_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Find and replace 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 1 - Find 9 | ############################## 10 | 11 | ## Question 1 ## 12 | 13 | 14 | def find_in(string,substring): 15 | return substring in string 16 | 17 | # Test 18 | print("--- With 'in' ---") 19 | 20 | string = "TO BE OR NOT TO BE" 21 | substring = "NOT" 22 | print(find_in(string,substring)) 23 | 24 | 25 | ## Question 2 ## 26 | 27 | def python_find(string,substring): 28 | position = string.find(substring) 29 | return position 30 | 31 | # Test 32 | print("--- With find() ---") 33 | 34 | position = python_find(string,substring) 35 | print(position) 36 | 37 | position = python_find(string,"XYZ") 38 | print(position) 39 | 40 | ## Question 3 ## 41 | 42 | def find_index(string,substring): 43 | position = string.index(substring) 44 | return position 45 | 46 | # Test 47 | print("--- With index() ---") 48 | 49 | position = find_index(string,substring) 50 | print(position) 51 | 52 | # position = find_index(string,"XYZ") 53 | # print(position) 54 | 55 | 56 | ## Question 4 ## 57 | 58 | 59 | def myfind(string,substring): 60 | len_string = len(string) 61 | len_substring = len(substring) 62 | for i in range(len_string-len_substring+1): 63 | found = True 64 | for j in range(len_substring): 65 | if string[i+j] != substring[j]: 66 | found = False 67 | break 68 | if found == True: 69 | return i 70 | return None 71 | 72 | # Test 73 | 74 | print("--- Your own function ---") 75 | 76 | position = myfind(string,substring) 77 | print(position) 78 | 79 | position = myfind(string,"XYZ") 80 | print(position) 81 | 82 | -------------------------------------------------------------------------------- /functions/fig-functions-lesson-1.tikz: -------------------------------------------------------------------------------- 1 | \usetikzlibrary{positioning} 2 | \begin{tikzpicture}[scale=1, every node/.style={transform shape}] 3 | \Large 4 | \node[right] (A) at (0,0) {\texttt{def}}; 5 | \node[right,right=-0.5em of A] (B) {\texttt{my\_function}}; 6 | \node[right,right=-1em of B] (C) {\texttt{()}}; 7 | \node[right,right=-1em of C] (D) {\texttt{:}}; 8 | 9 | \node[right] (E) at (1,-0.5) {\texttt{instruction\_1}}; 10 | \node[right] at (1,-1) {\texttt{instruction\_2}}; 11 | \node[right] at (1,-1.5) {\texttt{...}}; 12 | \node[right] (F) at (1,-2) {\texttt{return}}; 13 | 14 | \draw[<-,>=latex,ultra thick, red] (A.north) to[bend left] (7,3) node[right] {keyword "\texttt{def}"}; 15 | \draw[<-,>=latex,ultra thick, red] (B.north) to[bend left] (7,2.2) node[right] {well-chosen name}; 16 | \draw[<-,>=latex,ultra thick, red] (C.north) to[bend left] (7,1.4) node[right] {parentheses}; 17 | \draw[<-,>=latex,ultra thick, red] (D.north) to[bend left] (7,0.6) node[right] {colon}; 18 | 19 | \draw[|-|,ultra thick, red] (5.5,-0.3)--++(0,-1.5); 20 | \draw[ultra thick, red] (5.5,-1) to[bend right] (7,-0.8) node[right] {instructions}; 21 | 22 | \draw[<-,>=latex,ultra thick, red] (F.south) to[bend right] (7,-2.5) node[right] {end of the function}; 23 | 24 | \end{tikzpicture} -------------------------------------------------------------------------------- /functions/fig-functions-lesson-2.tikz: -------------------------------------------------------------------------------- 1 | \usetikzlibrary{positioning} 2 | \begin{tikzpicture}[scale=1, every node/.style={transform shape}] 3 | \Large 4 | \node[right,darkgray] (A) at (0,0.6) {\texttt{\# Definition of the function}}; 5 | \node[right] (A) at (0,0) {\texttt{def}}; 6 | \node[right,right=-0.5em of A] (B) {\texttt{my\_function}}; 7 | \node[right,right=-1em of B] (C) {\texttt{(param)}}; 8 | \node[right,right=-1em of C] (D) {\texttt{:}}; 9 | 10 | \node[right] (E) at (1,-0.5) {\texttt{instruction\_1}}; 11 | \node[right] at (1,-1) {\texttt{instruction\_2}}; 12 | \node[right] at (1,-1.5) {\texttt{...}}; 13 | \node[right] (F) at (1,-2) {\texttt{return}}; 14 | \node[right,right=-0.5em of F] (G) {\texttt{result}}; 15 | 16 | % \draw[<-,>=latex,ultra thick, red] (A.north) to[bend left] (7,3) node[right] {mot reserv\'e}; 17 | % \draw[<-,>=latex,ultra thick, red] (B.north) to[bend left] (7,2.2) node[right] {nom bien choisi}; 18 | \draw[<-,>=latex,ultra thick, red] (C.south) to[bend right=50] (8,-1.2) node[right] {a parameter}; 19 | % \draw[<-,>=latex,ultra thick, red] (D.north) to[bend left] (7,0.6) node[right] {deux points}; 20 | 21 | % \draw[|-|,ultra thick, red] (5.5,-0.3)--++(0,-1.5); 22 | % \draw[ultra thick, red] (5.5,-1) to[bend right] (7,-0.8) node[right] {les instructions}; 23 | 24 | \draw[<-,>=latex,ultra thick, red] (G.south) to[bend right=40] (8,-2.5) node[right] {returns the result}; 25 | 26 | \node[right,darkgray] (A) at (0,-3.9) {\texttt{\# Call of the function}}; 27 | \node[right] at (0,-4.5) {\texttt{x = 7}}; 28 | \node[right] (AA) at (0,-5) {\texttt{val = }}; 29 | \node[right,right=-0.5em of AA] (BB) {\texttt{my\_function}}; 30 | \node[right,right=-1em of BB] (CC) {\texttt{(x)}}; 31 | \draw[<-,>=latex,ultra thick, red] (AA.south) to[bend right] (8,-8.5) node[right] {returned result}; 32 | 33 | \draw[<-,>=latex,ultra thick, red] (BB.south) to[bend right] (8,-7.5) node[right] {call of the function}; 34 | \draw[<-,>=latex,ultra thick, red] (CC.south) to[bend right] (8,-6) node[right,text width = 7cm] {argument}; 35 | 36 | \end{tikzpicture} -------------------------------------------------------------------------------- /functions/fig-functions-lesson-3.tikz: -------------------------------------------------------------------------------- 1 | \usetikzlibrary{positioning} 2 | \begin{tikzpicture}[scale=1, every node/.style={transform shape}] 3 | \Large 4 | \node[right] (A) at (0,0) {\texttt{def}}; 5 | \node[right,right=-0.5em of A] (B) {\texttt{my\_function}}; 6 | \node[right,right=-1em of B] (C) {\texttt{(param1,param2)}}; 7 | \node[right,right=-1em of C] (D) {\texttt{:}}; 8 | 9 | \node[right] (B) at (1,-1) {\texttt{""" My function does this and that. """}}; 10 | 11 | \node[right] (E) at (1,-2) {\texttt{if param1 == param2:}}; 12 | \node[right] (EE) at (2,-2.5) {\texttt{return 0,0,0}}; 13 | \node[right] at (1,-3.5) {\texttt{other instructions...}}; 14 | 15 | 16 | % \node[right] at (1,-2.5) {\texttt{...}}; 17 | \node[right] (F) at (1,-4.5) {\texttt{return}}; 18 | \node[right,right=-0.5em of F] (G) {\texttt{value1, value2, value3}}; 19 | 20 | \draw[<-,>=latex,ultra thick, red] (C.north) to[bend left] (8,1.5) node[right] {one or several parameters}; 21 | 22 | \draw[<-,>=latex,ultra thick, red] (B.west) to[bend right=70] (0,-6.5) node[right] {function documentation}; 23 | 24 | \draw[<-,>=latex,ultra thick, red] (EE.east) to[bend right=10] (8,-2.5) node[right, text width = 7cm] {immediate termination of the function in this case}; 25 | 26 | \draw[<-,>=latex,ultra thick, red] (G.south) to[bend right] (8,-6) node[right] {returns one or several values}; 27 | 28 | \end{tikzpicture} -------------------------------------------------------------------------------- /functions/functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/functions/functions.pdf -------------------------------------------------------------------------------- /functions/functions_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Functions 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 3 - Turtle 9 | ############################## 10 | 11 | from turtle import * 12 | width(5) # Width of the pencil 13 | 14 | ############################## 15 | ## Question 1 ## 16 | 17 | def triangle(): 18 | color('red') 19 | forward(200) 20 | left(120) 21 | forward(200) 22 | left(120) 23 | forward(200) 24 | return 25 | 26 | 27 | # Test 28 | # triangle() 29 | # exitonclick() 30 | 31 | ############################## 32 | ## Question 2 ## 33 | 34 | def square(): 35 | color('green') 36 | for i in range(4): 37 | forward(200) 38 | left(90) 39 | return 40 | 41 | 42 | # Test 43 | # square() 44 | # exitonclick() 45 | 46 | 47 | ############################## 48 | ## Question 3 ## 49 | 50 | def hexagon(length): 51 | color('blue') 52 | for i in range(6): 53 | forward(length) 54 | left(60) 55 | return 56 | 57 | 58 | # Test 59 | # hexagon(100) 60 | # exitonclick() 61 | 62 | 63 | ############################## 64 | ## Question 4 ## 65 | 66 | def polygon(n,length): 67 | color('purple') 68 | angle = 360/n 69 | for i in range(n): 70 | forward(length) 71 | left(angle) 72 | return 73 | 74 | 75 | # Test 76 | # polygon(10,70) 77 | # exitonclick() 78 | 79 | # Test all 80 | up() 81 | goto(-450,0) 82 | down() 83 | triangle() 84 | up() 85 | goto(-200,0) 86 | setheading(0) 87 | down() 88 | square() 89 | up() 90 | goto(100,0) 91 | setheading(0) 92 | down() 93 | hexagon(100) 94 | up() 95 | goto(320,0) 96 | setheading(0) 97 | down() 98 | polygon(8,70) 99 | up() 100 | exitonclick() -------------------------------------------------------------------------------- /functions/functions_lesson.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Functions 4 | ############################## 5 | 6 | 7 | 8 | ############################## 9 | # Lesson 1 10 | ############################## 11 | 12 | ################################################## 13 | 14 | def say_hello(): 15 | print("Hello world!") 16 | return 17 | 18 | # Call 19 | say_hello() 20 | say_hello() 21 | 22 | ################################################## 23 | def print_squares(): 24 | for i in range(20): 25 | print(i**2) 26 | return 27 | 28 | # Call 29 | print_squares() 30 | 31 | 32 | ############################## 33 | # Lesson 2 34 | ############################## 35 | 36 | ################################################## 37 | def display_month(number): 38 | if number == 1: 39 | print("We are in January.") 40 | if number == 2: 41 | print("We are in February.") 42 | if number == 3: 43 | print("We are in March.") 44 | # etc. 45 | return 46 | 47 | # Call 48 | display_month(2) 49 | 50 | 51 | ################################################## 52 | def compute_cube(a): 53 | cube = a * a * a # or a**3 54 | return cube 55 | 56 | # Call 57 | x = 3 58 | y = 4 59 | z = compute_cube(x) + compute_cube(y) 60 | print(z) 61 | 62 | 63 | ############################## 64 | # Lesson 2 65 | ############################## 66 | 67 | ################################################## 68 | def sum_product(a,b): 69 | """ Computes the sum and product of two numbers. """ 70 | s = a + b 71 | p = a * b 72 | return s, p 73 | 74 | # Call 75 | mysum, myprod = sum_product(6,7) 76 | print(mysum,myprod) 77 | 78 | ############################## 79 | # Lesson - Local variable 80 | ############################## 81 | 82 | x = 7 83 | 84 | def add_one(x): 85 | x = x + 1 86 | return x 87 | 88 | def double(x): 89 | x = 2*x 90 | return x 91 | 92 | print(x) 93 | print(add_one(x)) 94 | print(double(x)) 95 | print(x) 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /functions/screen-functions-tortue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/functions/screen-functions-tortue.png -------------------------------------------------------------------------------- /guide/ecran-markdown-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/guide/ecran-markdown-8.png -------------------------------------------------------------------------------- /guide/ecran-markdown-8.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[height=5cm]{ecran-markdown-8.png}}; 4 | \begin{scope}[x={(image.south east)},y={(image.north west)}] 5 | 6 | \draw[->,>=latex,ultra thick,blue] (0,0.9)--++(0.9,0) node[above]{$x$}; 7 | \draw[->,>=latex,ultra thick,blue] (0,0.9)--++(0,-0.9) node[left]{$y$}; 8 | \coordinate (A) at (0.135,0.855); 9 | \coordinate (B) at (0.34,0.283); 10 | \coordinate (NW) at (0.41,0.707); 11 | 12 | \fill[black] (A) circle (4pt) node[below left] {$(x_1,y_1)$}; 13 | \fill[black] (B) circle (4pt) node[below right] {$(x_2,y_2)$}; 14 | \fill[red] (NW) circle (4pt) ; 15 | \draw[<-,>=latex,ultra thick,red] (NW) to[bend left=10] (0.8,0.8) node[right]{ancre Nord-Ouest}; 16 | 17 | \fill[blue] (0,0.9) circle (4pt) node[above left] {$(0,0)$}; 18 | 19 | 20 | \end{scope} 21 | 22 | \end{tikzpicture} 23 | -------------------------------------------------------------------------------- /guide/fig-arbre.tikz: -------------------------------------------------------------------------------- 1 | \tikzstyle{line} = [draw, thick] 2 | 3 | \begin{tikzpicture} 4 | 5 | \path node(P1) {$5$ }; 6 | \path (P1)+(2,0) node(P2) {$4$}; 7 | \path (P1)+(1,-1.5) node(P3){$+$}; 8 | \path (P3)+(2,0) node(P4) {$3$}; 9 | \path (P3)+(1,-1.5) node(P5){$\times$}; 10 | 11 | % Draw arrows between elements 12 | \path[line] (P1.south) -- node [above] {} (P3); 13 | \path[line] (P2.south) -- node [above] {} (P3); 14 | \path[line] (P3.south) -- node [above] {} (P5); 15 | \path[line] (P4.south) -- node [above] {} (P5); 16 | 17 | 18 | \end{tikzpicture} 19 | -------------------------------------------------------------------------------- /guide/fig-tableau.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | \node at (0.5,0.5) {\bf 8}; 5 | \node at (1.5,0.5) {\bf 6}; 6 | \node at (2.5,0.5) {\bf 5}; 7 | \node at (0.5,1.5) {\bf 15}; 8 | \node at (1.5,1.5) {\bf 19}; 9 | \node at (2.5,1.5) {\bf 4}; 10 | \node at (0.5,2.5) {\bf 3}; 11 | \node at (1.5,2.5) {\bf 5}; 12 | \node at (2.5,2.5) {\bf 7}; 13 | \node at (0.5,3.5) {\bf 2}; 14 | \node at (1.5,3.5) {\bf 14}; 15 | \node at (2.5,3.5) {\bf 5}; 16 | 17 | \draw[thick] (0,0) grid ++(3,4); 18 | 19 | % \node at (3,-0.7) {\bf Un tableau avec $5$ blocs ($N=4$, $M=6$)}; 20 | 21 | \draw[->,>=latex,very thick] (0,5) to node[midway, above] {index $j$} ++(3,0) ; 22 | \draw[->,>=latex,very thick] (-1.5,4) to node[midway, left] {index $i$} ++(0,-4) ; 23 | 24 | \node[scale=0.7,above] at (0.5,4) {$j=0$}; 25 | \node[scale=0.7,above] at (1.5,4) {$j=1$}; 26 | \node[scale=0.7,above] at (2.5,4) {$j=2$}; 27 | 28 | 29 | \node[scale=0.7,left] at (0,3.5) {$i=0$}; 30 | \node[scale=0.7,left] at (0,2.5) {$i=1$}; 31 | \node[scale=0.7,left] at (0,1.5) {$i=2$}; 32 | \node[scale=0.7,left] at (0,0.5) {$i=3$}; 33 | 34 | 35 | \end{tikzpicture} -------------------------------------------------------------------------------- /guide/guide-biblio.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/guide/guide-biblio.pdf -------------------------------------------------------------------------------- /guide/guide-functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/guide/guide-functions.pdf -------------------------------------------------------------------------------- /guide/guide-python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/guide/guide-python.pdf -------------------------------------------------------------------------------- /guide/guide_erreur.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Guide - Erreurs classiques 4 | ############################## 5 | 6 | 7 | ####################### 8 | # Erreur d'indentation 9 | # a = 3 10 | # b = 2 11 | 12 | 13 | ####################### 14 | # Erreur de syntaxe 15 | 16 | # while x >= 0 17 | # x = x - 1 18 | 19 | 20 | # chaine = Coucou 21 | 22 | 23 | # print("Coucou" 24 | 25 | 26 | # val = 0 27 | # if val = 1: 28 | # print("ok") 29 | 30 | 31 | 32 | ####################### 33 | # Erreur de type 34 | 35 | # n = 7.0 36 | # for i in range(n): 37 | # print(i) 38 | 39 | 40 | # from math import * 41 | # x = "9" 42 | # sqrt(x) 43 | 44 | 45 | ####################### 46 | # Erreur de nom 47 | 48 | # x = sqrt(2) 49 | 50 | 51 | # if y != 0: 52 | # y = y - 1 53 | 54 | 55 | # from math import * 56 | # gcd(12) 57 | 58 | 59 | # produit(6,7) 60 | 61 | # def produit(a,b): 62 | # return a*b 63 | 64 | 65 | ####################### 66 | # Boucle et liste 67 | 68 | for i in range(10): 69 | print(i ** 2) 70 | 71 | 72 | # liste = [1,2,3,4] 73 | # print(liste[4]) 74 | 75 | n = 0 76 | while n != "10": 77 | n = n + 1 78 | print(n) 79 | 80 | ####################### 81 | # Exercice 82 | 83 | ####################### 84 | a = 7 85 | if (a == 2) or (a >= 5) : 86 | b = a - 2 87 | c = a + 2 88 | else: 89 | b = a // 2 90 | c = 2 * a 91 | print(a,b,c) 92 | 93 | ####################### 94 | # a == 7 95 | # if (a = 2) or (a >= 5) 96 | # b = a - 2 97 | # c = a + 2 98 | # else 99 | # b = a // 2 100 | # c = 2 * a 101 | # print(a b c) 102 | -------------------------------------------------------------------------------- /guide/guide_format.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Guide - Mise en formae 4 | ############################## 5 | 6 | # Alignement à gauche 7 | print('{:10}'.format('Test')) 8 | 9 | # Alignement à droite 10 | print('{:>10}'.format('Test')) 11 | 12 | # Centré 13 | print('{:^10}'.format('Test')) 14 | 15 | 16 | 17 | # Entier 18 | print('{:d}'.format(456)) 19 | 20 | # Entier sur longueur fixée 21 | print('{:6d}'.format(456)) 22 | 23 | # Entier avec 0 non significatifs 24 | print('{:06d}'.format(456)) 25 | 26 | 27 | 28 | # Nombre flottant 29 | print('{:f}'.format(3.141592653589793)) 30 | 31 | # Flottant avec nb de chiffesd après la virgules 32 | print('{:.8f}'.format(3.141592653589793)) 33 | 34 | # Nombre flottant sur longueur fixée 35 | print('{:8.4f}'.format(3.141592653589793)) 36 | 37 | # Flottant avec 0 non significatifs 38 | print('{:08.4f}'.format(3.141592653589793)) 39 | -------------------------------------------------------------------------------- /guide/guide_python.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Guide Python - Functions 4 | ############################## 5 | 6 | def sum_product(a,b): 7 | """ Computes the sum and product of two numbers. """ 8 | s = a + b 9 | p = a * b 10 | return s, p 11 | 12 | # Call of the function 13 | mysum, myprod = sum_product(6,7) # Results 14 | print("The sum is:",mysum) # Display 15 | print("The product is:",myprod) # Display -------------------------------------------------------------------------------- /guide/screen-markdown-8-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/guide/screen-markdown-8-en.png -------------------------------------------------------------------------------- /guide/screen-markdown-8-en.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[height=5cm]{screen-markdown-8-en.png}}; 4 | \begin{scope}[x={(image.south east)},y={(image.north west)}] 5 | 6 | \draw[->,>=latex,ultra thick,blue] (0,0.9)--++(1,0) node[above]{$x$}; 7 | \draw[->,>=latex,ultra thick,blue] (0,0.9)--++(0,-0.9) node[left]{$y$}; 8 | \coordinate (A) at (0.15,0.75); 9 | \coordinate (B) at (0.35,0.2); 10 | 11 | \draw (A) rectangle (B); 12 | 13 | \coordinate (SW) at (0.49,0.65); 14 | 15 | \fill[black] (A) circle (4pt) node[below left] {$(x_1,y_1)$}; 16 | \fill[black] (B) circle (4pt) node[below right] {$(x_2,y_2)$}; 17 | \fill[red] (SW) circle (4pt) ; 18 | \draw[<-,>=latex,ultra thick,red] (SW) to[bend right=10] (0.7,0.4) node[right]{South West anchor}; 19 | 20 | \fill[blue] (0,0.9) circle (4pt) node[above left] {$(0,0)$}; 21 | 22 | 23 | \end{scope} 24 | 25 | \end{tikzpicture} 26 | -------------------------------------------------------------------------------- /hello_world/fig_trapezoid.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \filldraw[blue,fill=blue!10,very thick] (0,0) 4 | -- node[midway, below,black]{$B=7$} ++(7,0) 5 | -- ++ (-2,3) 6 | --node[midway, above,black]{$b=4$} ++(-4,0) 7 | --cycle; 8 | 9 | \draw (4.5,0) -- ++(0,3) node[midway,left]{$h=3$}; 10 | 11 | \end{tikzpicture} -------------------------------------------------------------------------------- /hello_world/hello_world.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/hello_world/hello_world.pdf -------------------------------------------------------------------------------- /hello_world/hello_world_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Hello world! 4 | ############################## 5 | 6 | ############################## 7 | # Activity 1 - Numbers 8 | ############################## 9 | 10 | ############################## 11 | # Cours 12 | print("--- Lesson ---") 13 | # Display a sentence 14 | print("Hello world!") 15 | 16 | # Addition 17 | 5+7 18 | print(5+7) 19 | 20 | # Multiplication 21 | print(6*7) 22 | 23 | print(3*(12+5)) 24 | 25 | print(3*1.5) 26 | 27 | # Power 28 | 29 | print(3**2) 30 | 31 | print(10**-3) 32 | 33 | # Division of real number 34 | 35 | print(14/4) 36 | 37 | print(1/3) 38 | 39 | # Euclidean division and modulo 40 | 41 | print(14//4) 42 | 43 | print(14%4) 44 | 45 | 46 | 47 | ############################## 48 | # Questions 49 | 50 | # Q1 51 | # Number of second in a century 52 | print("--- Question 1 ---") 53 | print(100 * 365 * 24 * 60 * 60) 54 | 55 | 56 | # Q2 57 | # When it is greater than one billion 58 | print("--- Question 2 ---") 59 | print((1+2)*(3+4)*(5+6)*(7+8)*(9+10)*(11+12)*(13+14)*(15+16)) 60 | 61 | 62 | # Q3 63 | # Last three digits of 123456789 * 123456789 * ... 64 | print("--- Question 3 ---") 65 | print(123456789 ** 7) 66 | 67 | 68 | # Q4 69 | # First 1/n with a period of 7 70 | print("--- Question 4 ---") 71 | print(1/7) # Période 6 72 | print(1/239) # Période 7 73 | 74 | 75 | # Q5 76 | # Find a number knowing two divisions and a remainder 77 | print("--- Question 5 ---") 78 | # for n in range(1175,1190): 79 | # print(n,n//11,n//13,n%7) 80 | 81 | print(1182//11) 82 | print(1182//13) 83 | print(1182%7) 84 | 85 | -------------------------------------------------------------------------------- /hello_world/hello_world_2.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Hello world! 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 2 - Variables 9 | ############################## 10 | 11 | 12 | ############################## 13 | # Lesson 14 | 15 | # C1 - variables 16 | 17 | a = 3 # One variable 18 | b = 5 # Another variable 19 | 20 | print("The sum is",a+b) # Display the sum 21 | print("The product",a*b) # Display the product 22 | 23 | c = b**a # New variable... 24 | print(c) # ... that is displayed 25 | 26 | 27 | # C2 - area of a triangle 28 | 29 | base = 8 30 | height = 3 31 | area = base * height / 2 32 | print(area) 33 | # print(Area) # !! Error !! 34 | 35 | 36 | # C3 - Re-assignement 37 | 38 | S = 1000 39 | S = S + 100 40 | S = S + 200 41 | S = S - 50 42 | print(S) 43 | 44 | 45 | ############################## 46 | # Questions 47 | 48 | # Q1 49 | 50 | # Areas - Volumes 51 | 52 | # Trapezoid: right namming 53 | B, b, h = 7, 4, 3 54 | area = (B + b) * h / 2 55 | print("The area is",area) 56 | 57 | # Box 58 | L, l, h = 10,8,3 59 | volume = L * l * h 60 | print(volume) 61 | 62 | # Disc 63 | PI = 3.14 64 | R = 10 65 | area = PI * R**2 66 | print(area) 67 | 68 | 69 | # Q2 70 | # Put the lines back in order so that at the end x has the value 46. 71 | x = 7 72 | y = 2*x 73 | y = y - 1 74 | x = x + 3*y 75 | print(x) 76 | 77 | 78 | # Q3 79 | # Interest of 10% 80 | S = 1000 81 | S = S * 1.1 82 | S = S * 1.1 83 | S = S * 1.1 84 | 85 | 86 | # Q4 87 | 88 | # Good way to exchange the values of a and b 89 | 90 | # Wrong 91 | a = 11 92 | b = 9 93 | a = b 94 | b = a 95 | print(a,b) 96 | 97 | # Wrong 98 | a = 11 99 | b = 9 100 | c = b 101 | a = b 102 | b = c 103 | print(a,b) 104 | 105 | # Wrong 106 | a = 11 107 | b = 9 108 | c = a 109 | a = c 110 | c = b 111 | b = c 112 | 113 | print(a,b) 114 | 115 | # Good 116 | a = 11 117 | b = 9 118 | c = a 119 | a = b 120 | b = c 121 | print(a,b) 122 | 123 | -------------------------------------------------------------------------------- /hello_world/hello_world_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Hello world! 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 3 - Use functions 9 | ############################## 10 | 11 | 12 | ############################## 13 | # Cours 14 | 15 | # C1 - functions 16 | 17 | print("Hi there.") 18 | 19 | x = float("+1.234567") 20 | print(x) 21 | 22 | 23 | # C2 - math module 24 | 25 | from math import * 26 | 27 | x = sqrt(2) 28 | print(x) 29 | print(x**2) 30 | 31 | # C3 - sine and cosine 32 | 33 | angle = pi/2 34 | print(angle) 35 | print(sin(angle)) 36 | 37 | 38 | # C4 - decimal number to integer 39 | 40 | x = 3.6 41 | print(round(x)) 42 | print(floor(x)) 43 | print(ceil(x)) 44 | 45 | 46 | ############################## 47 | # Questions 48 | 49 | # Q1 50 | # gcd 51 | print(gcd(13*121,13*122)) 52 | 53 | a = 101*103 54 | b = 102*103 55 | print(a,b) 56 | lcm = a * b // gcd(a,b) 57 | print(lcm) 58 | 59 | 60 | # Q2 61 | # Absolute value 62 | x = 3.85 63 | print(abs(x**2-15)) 64 | print(round(2*x)) 65 | print(floor(3*x)) 66 | print(ceil(4*x)) 67 | 68 | 69 | # Q3 70 | # Angle 71 | angle = pi/7 72 | x = cos(angle)**2 + sin(angle)**2 73 | print(x) 74 | 75 | -------------------------------------------------------------------------------- /hello_world/hello_world_4.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Hello world! 4 | ############################## 5 | 6 | 7 | from math import * 8 | 9 | 10 | ############################## 11 | # Activity 4 - Loop "for" 12 | ############################## 13 | 14 | ############################## 15 | # Cours 16 | 17 | # C1 - Loop "for" 18 | 19 | for i in range(10): 20 | print(i*i) 21 | 22 | 23 | # C2 - Loop "for" 24 | 25 | mysum = 0 26 | for i in range(20): 27 | mysum = mysum + i 28 | print(mysum) 29 | 30 | 31 | # C3 32 | 33 | print(list(range(10))) 34 | print(list(range(10,20))) 35 | print(list(range(10,20,2))) 36 | 37 | 38 | # C4 - Nesting of loops 39 | 40 | for x in [10,20,30,40,50]: 41 | for y in [3,7]: 42 | print(x+y) 43 | 44 | ############################## 45 | # Questions 46 | 47 | # Q1 48 | # Cubes 49 | for i in range(101): 50 | print(i**3) 51 | 52 | for i in range(10,21): 53 | print(i**4) 54 | 55 | for i in range(0,101,5): 56 | print(sqrt(i)) 57 | 58 | 59 | # Q2 60 | # Powers of 2 61 | for k in range(1,11): 62 | print(2**k) 63 | 64 | 65 | # Q3 66 | # Minimum of a function by scanning 67 | for i in range(101): 68 | x = i/100 69 | y = x**3 - x**2 - 1/4*x + 1 70 | print("x =",x,"y =",y) 71 | 72 | # Q4 73 | # Volume of ball equal to 100 74 | for i in range(50): 75 | R = i/10 76 | V = 4/3 * 3.14 * R**3 77 | print("R =",R,"V =",V) 78 | 79 | -------------------------------------------------------------------------------- /hello_world/hello_world_5.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Hello world! 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 5 - Loop "for" (continued) 9 | ############################## 10 | 11 | # Questions 12 | 13 | # Q1 14 | # Sum of the squares 15 | n = 20 16 | mysum = 0 17 | for i in range(n+1): 18 | mysum = mysum + i**2 19 | print(mysum) 20 | 21 | 22 | # Q2 23 | # Products 24 | n = 19 25 | myproduct = 1 26 | for i in range(1,n+1,2): 27 | myproduct = myproduct * i 28 | print(myproduct) 29 | 30 | 31 | # Q3 32 | # Multiplication tables 33 | for a in range(11): 34 | for b in range(11): 35 | print(a,"x",b,"=",a*b) -------------------------------------------------------------------------------- /hello_world/test_period.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Premiers pas 4 | ############################## 5 | 6 | ############################## 7 | # Activité 1 - Nombres 8 | ############################## 9 | 10 | from math import * 11 | epsilon = 10**-8 12 | 13 | for n in range(1,1000): 14 | e = floor(log(n,10)) 15 | m = 10**e * ( 1/n*10**(7) - 1/n ) 16 | p = m - round(m) 17 | # print(e,n,m,p,1/n) 18 | if abs(p) < epsilon: 19 | print("--->",n,1/n) 20 | 21 | # Q4 22 | # Premier 1/n avec période 7 23 | print("--- Question 4 ---") 24 | print(1/7) # Période 6 25 | print(1/239) # Période 7 26 | 27 | -------------------------------------------------------------------------------- /ifthen/fig-ifthen-0.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \begin{scope}[rotate=5] 4 | 5 | \coordinate (A) at (0,0); 6 | \coordinate (B) at (8,0); 7 | 8 | %\draw[ultra thick,blue] (A) circle (5 cm); 9 | %\draw[ultra thick,blue] (B) circle (4 cm); 10 | 11 | \coordinate (C) at (24:5); 12 | % \fill (C) circle (5pt); 13 | 14 | 15 | \draw[ultra thick,blue] 16 | (A) -- node[midway,below,black]{$c$} (B) 17 | -- node[midway,above right,black]{$a$}(C) 18 | -- node[midway,above left,black]{$b$} cycle; 19 | 20 | \node[left] at (A) {$A$}; 21 | \node[right] at (B) {$B$}; 22 | \node[above] at (C) {$C$}; 23 | 24 | \draw[double] (0:1) arc (0:24:1) node[midway,right] {$\alpha$}; 25 | \draw[double] (7,0) arc (180:150:1) node[midway,left] {$\beta$}; 26 | 27 | \draw[double] (24:4) arc (-180+24:-30:1) node[midway,below] {$\gamma$}; 28 | \end{scope} 29 | 30 | \end{tikzpicture} -------------------------------------------------------------------------------- /ifthen/fig-ifthen-1.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \begin{scope}[rotate=5] 4 | 5 | \coordinate (A) at (0,0); 6 | \coordinate (B) at (8,0); 7 | 8 | %\draw[ultra thick,blue] (A) circle (5 cm); 9 | %\draw[ultra thick,blue] (B) circle (4 cm); 10 | 11 | \coordinate (C) at (24:5); 12 | % \fill (C) circle (5pt); 13 | 14 | 15 | \draw[ultra thick,blue] 16 | (A) -- node[midway,below,black]{$c$} (B) 17 | -- node[midway,above right,black]{$a$}(C) 18 | -- node[midway,above left,black]{$b$} cycle; 19 | % 20 | % \node[left] at (A) {$A$}; 21 | % \node[right] at (B) {$B$}; 22 | % \node[above] at (C) {$C$}; 23 | % 24 | % \draw[double] (0:1) arc (0:24:1) node[midway,right] {$\alpha$}; 25 | % \draw[double] (7,0) arc (180:150:1) node[midway,left] {$\beta$}; 26 | % \draw[double] (24:4) arc (-180+24:-30:1) node[midway,below] {$\gamma$}; 27 | 28 | \end{scope} 29 | 30 | \end{tikzpicture} -------------------------------------------------------------------------------- /ifthen/fig-ifthen-3.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \begin{scope}[rotate=5] 4 | 5 | \coordinate (A) at (0,0); 6 | \coordinate (B) at (8,0); 7 | 8 | %\draw[ultra thick,blue] (A) circle (5 cm); 9 | %\draw[ultra thick,blue] (B) circle (4 cm); 10 | 11 | \coordinate (C) at (24:5); 12 | % \fill (C) circle (5pt); 13 | 14 | 15 | \draw[ultra thick,blue] 16 | (A) -- node[midway,below,black]{$c$} (B) 17 | -- node[midway,above right,black]{$a$}(C) 18 | -- node[midway,above left,black]{$b$} cycle; 19 | 20 | % \node[left] at (A) {$A$}; 21 | % \node[right] at (B) {$B$}; 22 | % \node[above] at (C) {$C$}; 23 | 24 | \draw[double] (0:1) arc (0:24:1) node[midway,right] {$\alpha$}; 25 | \draw[double] (7,0) arc (180:150:1) node[midway,left] {$\beta$}; 26 | 27 | \draw[double] (24:4) arc (-180+24:-30:1) node[midway,below] {$\gamma$}; 28 | \end{scope} 29 | 30 | \end{tikzpicture} -------------------------------------------------------------------------------- /ifthen/fig-ifthen-lesson-1.tikz: -------------------------------------------------------------------------------- 1 | \usetikzlibrary{positioning} 2 | \begin{tikzpicture}[scale=1, every node/.style={transform shape}] 3 | \Large 4 | \node[right] (A) at (0,0) {\texttt{if}}; 5 | \node[right,right=-0.7em of A] (B) {\texttt{condition}}; 6 | \node[right,right=-0.8em of B] (C) {\texttt{:}}; 7 | 8 | 9 | \node[right] (E) at (1,-0.7) {\texttt{instruction\_1}}; 10 | \node[right] at (1,-1.4) {\texttt{instruction\_2}}; 11 | \node[right] at (1,-2.1) {\texttt{...}}; 12 | \node[right] (F) at (0,-2.8) {\texttt{other instructions}}; 13 | 14 | \draw[<-,>=latex,ultra thick, red] (A.north) to[bend left] (9,3) node[right] {keyword "\texttt{if}"}; 15 | \draw[<-,>=latex,ultra thick, red] (B.north) to[bend left] (9,2) node[right] {a condition}; 16 | \draw[<-,>=latex,ultra thick, red] (C.north) to[bend left] (9,1) node[right] {colon}; 17 | 18 | \draw[|-|,ultra thick, red] (5.5,-0.3)--++(0,-2.1); 19 | \draw[ultra thick, red] (5.5,-1.2) to[bend right] (10,-0.5) node[right] {indented block}; 20 | \node[right,red] at (10,-1.25) {will be executed only}; 21 | \node[right,red] at (10,-1.9) {if the condition is true}; 22 | 23 | \draw[<-,>=latex,ultra thick, red] (F.east) to[bend left] (9,-3.2) node[right] {program continuation}; 24 | 25 | \end{tikzpicture} -------------------------------------------------------------------------------- /ifthen/fig-ifthen-lesson-2.tikz: -------------------------------------------------------------------------------- 1 | \usetikzlibrary{positioning} 2 | \begin{tikzpicture}[scale=1, every node/.style={transform shape}] 3 | \Large 4 | \node[right] (A) at (0,0) {\texttt{if}}; 5 | \node[right,right=-0.7em of A] (B) {\texttt{condition}}; 6 | \node[right,right=-0.8em of B] (C) {\texttt{:}}; 7 | 8 | 9 | \node[right] (E) at (1,-0.7) {\texttt{instruction}}; 10 | \node[right] at (1,-1.4) {\texttt{instruction}}; 11 | \node[right] at (1,-2.1) {\texttt{...}}; 12 | 13 | \node[right] (AA) at (0,-2.8) {\texttt{else:}}; 14 | 15 | \node[right] (E) at (1,-3.5) {\texttt{instruction}}; 16 | \node[right] at (1,-4.2) {\texttt{...}}; 17 | 18 | 19 | \node[right] (F) at (0,-5) {\texttt{other instructions}}; 20 | 21 | % \draw[<-,>=latex,ultra thick, red] (A.north) to[bend left] (9,3) node[right] {mot reserv\'e "\texttt{if}"}; 22 | % \draw[<-,>=latex,ultra thick, red] (B.north) to[bend left] (9,2) node[right] {une condition}; 23 | % \draw[<-,>=latex,ultra thick, red] (C.north) to[bend left] (9,1) node[right] {deux points}; 24 | 25 | 26 | \draw[|-|,ultra thick, red] (5.5,-0.3)--++(0,-2.1); 27 | \draw[ultra thick, red] (5.5,-1.2) to[bend right] (10,-0.5) node[right] {this block will be executed}; 28 | \node[right,red] at (10,-1.3) {if the condition is true}; 29 | 30 | 31 | \draw[|-|,ultra thick, red] (5.5,-3.1)--++(0,-1.5); 32 | 33 | \draw[ultra thick, red] (5.5,-3.9) to[bend right] (10,-3.5) node[right] {this block will be executed}; 34 | \node[right,red] at (10,-4.3) {if the condition is not true}; 35 | 36 | % \draw[<-,>=latex,ultra thick, red] (F.east) to[bend left] (9,-3.2) node[right] {program continuation}; 37 | 38 | 39 | 40 | 41 | 42 | \end{tikzpicture} -------------------------------------------------------------------------------- /ifthen/ifthen.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ifthen/ifthen.pdf -------------------------------------------------------------------------------- /ifthen/ifthen_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # If ... then ... 4 | ############################## 5 | 6 | ############################## 7 | # Activity 1 - Quiz multiplications 8 | ############################## 9 | 10 | from random import * 11 | 12 | a = randint(1,10) 13 | b = randint(1,10) 14 | 15 | print("How much is the product",a,"times",b,"?") 16 | answer_str = input("Your answer: ") 17 | answer_int = int(answer_str) 18 | 19 | if answer_int == a*b: 20 | print("Well done!") 21 | else: 22 | print("Lost! The correct answer was",a*b) 23 | 24 | 25 | -------------------------------------------------------------------------------- /ifthen/ifthen_2.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # If ... then ... 4 | ############################## 5 | 6 | ############################## 7 | # Fctivity 2 - Turtle 8 | ############################## 9 | 10 | from turtle import * 11 | 12 | width(5) 13 | color('blue') 14 | 15 | mot = "FflFlFrFlFFlfFF" 16 | 17 | for c in mot: 18 | 19 | if c == "F": 20 | forward(100) 21 | 22 | if c == "f": 23 | up() 24 | forward(100) 25 | down() 26 | 27 | if c == "l": 28 | left(90) 29 | 30 | if c == "r": 31 | right(90) 32 | 33 | exitonclick() 34 | -------------------------------------------------------------------------------- /ifthen/ifthen_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # If ... then ... 4 | ############################## 5 | 6 | ############################## 7 | # Activity 3 - Digits of a integer 8 | ############################## 9 | 10 | 11 | ############################## 12 | ## Question 1 ## 13 | 14 | for t in range(10): 15 | for u in range(10): 16 | n = 10*t + u 17 | print(n) 18 | 19 | 20 | ############################## 21 | ## Question 2 ## 22 | 23 | for h in range(10): 24 | for t in range(10): 25 | for u in range(10): 26 | n = 100*h + 10*t + u 27 | if u == 3 and (h+t+u >= 15) and (t == 0 or t == 2 or t == 4 or t == 6 or t == 8): 28 | print(n) 29 | 30 | 31 | ############################## 32 | ## Question 3 ## 33 | 34 | count = 0 35 | 36 | for h in range(10): 37 | for t in range(10): 38 | for u in range(10): 39 | n = 100*h + 10*t + u 40 | if u == 3 and (h+t+u >= 15) and (t == 0 or t == 2 or t == 4 or t == 6 or t == 8): 41 | count = count + 1 42 | 43 | print("Total number of solutions:",count) -------------------------------------------------------------------------------- /ifthen/ifthen_4.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # If ... then ... 4 | ############################## 5 | 6 | ############################## 7 | # Activity 4 - Triangles 8 | ############################## 9 | 10 | 11 | # a,b,c = 3,4,5 12 | 13 | 14 | ############################## 15 | ## Question 1 ## 16 | 17 | a = 4 18 | b = 5 19 | c = 8 20 | print("Triangle",a,b,c) 21 | 22 | # Do we have a <= b <= c? 23 | 24 | if a <= b and b <= c: 25 | print("Lengths in the right order.") 26 | else: 27 | print("Lengths in the wrong order.") 28 | 29 | 30 | ############################## 31 | ## Question 2 ## 32 | 33 | # Can we construct a triangle from these three lengths? 34 | 35 | if a+b >= c: 36 | print("Such a triangle exists.") 37 | else: 38 | print("Such a triangle doesn't exist.") 39 | 40 | 41 | ############################## 42 | ## Question 3 ## 43 | 44 | # Is the triangle recantgle? 45 | 46 | if a**2 + b**2 == c**2: 47 | print("The triangle is rectangle.") 48 | else: 49 | print("The triangle is not rectangle.") 50 | 51 | 52 | ############################## 53 | ## Question 3 ## 54 | 55 | # Is the triangle equilateral? 56 | 57 | if (a == b) and (b == c) and (a == c): 58 | print("The triangle is equilateral.") 59 | else: 60 | print("The triangle is not equilateral.") 61 | 62 | 63 | ############################## 64 | ## Question 4 ## 65 | 66 | # Is the triangle isosceles? 67 | 68 | if (a == b) or (b == c) or (a == c): 69 | print("The triangle is isosceles.") 70 | else: 71 | print("The triangle is not isosceles.") 72 | 73 | 74 | ############################## 75 | ## Question 5 ## 76 | 77 | # Are all the angles acute? 78 | 79 | cosalpha = (-a**2 + b**2 + c**2)/(2*b*c) 80 | cosbeta = (a**2 - b**2 + c**2)/(2*a*c) 81 | cosgamma = (a**2 + b**2 - c**2)/(2*a*b) 82 | 83 | if (cosalpha >= 0) and (cosbeta >= 0) and (cosgamma >= 0): 84 | print("All the angles are acute.") 85 | else: 86 | print("Not all the angles are acute. (At least one of them is obtuse).") -------------------------------------------------------------------------------- /ifthen/ifthen_lesson.py: -------------------------------------------------------------------------------- 1 | ############################## 2 | # Lesson - If then 3 | ############################## 4 | 5 | 6 | speed = 120 # Try 100 7 | 8 | if speed > 110: 9 | print("Warning, you are driving too fast.") 10 | 11 | 12 | x = 7 # Try -5 13 | 14 | if x >= 0: 15 | print("The number is positive (or zero).") 16 | else: 17 | print("The number is negative.") 18 | 19 | 20 | -------------------------------------------------------------------------------- /ifthen/ifthen_lesson_input.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Si ... alors ... 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Lesson - Input 9 | ############################## 10 | 11 | 12 | 13 | first_name = input ("What's your name? ") 14 | print("Hello",first_name) 15 | 16 | age_str = input("How old are you? ") 17 | age = int(age_str) 18 | 19 | if age >= 18: 20 | print("You're an adult!") 21 | else: 22 | print("You're a minor!") 23 | 24 | -------------------------------------------------------------------------------- /ifthen/screen-ifthen-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ifthen/screen-ifthen-2.png -------------------------------------------------------------------------------- /images/fig-images-1.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=0.8, every node/.style={scale=1}] 2 | 3 | 4 | \draw[ultra thick,gray] (0,0) grid ++(8,8); 5 | 6 | \node[blue,scale=1] at (0.5,7.5) {\bf A}; 7 | \node[blue,scale=1] at (1.5,7.5) {\bf B}; 8 | \node[blue,scale=1] at (0.5,6.5) {\bf C}; 9 | \node[blue,scale=1] at (1.5,6.5) {\bf D}; 10 | 11 | \node[red,scale=1] at (2.5,7.5) {\bf a}; 12 | \node[red,scale=1] at (3.5,7.5) {\bf b}; 13 | \node[red,scale=1] at (2.5,6.5) {\bf c}; 14 | \node[red,scale=1] at (3.5,6.5) {\bf d}; 15 | 16 | \draw [->,>=latex,red!20,ultra thick,line width=7] (9,4) to ++(3,0); 17 | 18 | \node[scale=0.7] at (-0.8,7.5) {$i\!=\!0$}; 19 | \node[scale=0.7] at (-0.8,6.5) {$i\!=\!1$}; 20 | \node[scale=0.7] at (0.5,8.5) {$j\!=\!0$}; 21 | \node[scale=0.7] at (1.5,8.5) {$j\!=\!1$}; 22 | 23 | \begin{scope}[xshift=13cm] 24 | 25 | \draw[ultra thick,gray] (0,0) grid ++(8,8); 26 | \draw[line width=4,black!80] (0,4) -- ++(8,0); 27 | \draw[line width=4,black!80] (4,0) -- ++(0,8); 28 | 29 | \node[blue,scale=1] at (0.5,7.5) {\bf A}; 30 | \node[blue,scale=1] at (4.5,7.5) {\bf B}; 31 | \node[blue,scale=1] at (0.5,3.5) {\bf C}; 32 | \node[blue,scale=1] at (4.5,3.5) {\bf D}; 33 | 34 | \node[red,scale=1] at (1.5,7.5) {\bf a}; 35 | \node[red,scale=1] at (5.5,7.5) {\bf b}; 36 | \node[red,scale=1] at (1.5,3.5) {\bf c}; 37 | \node[red,scale=1] at (5.5,3.5) {\bf d}; 38 | 39 | \node[scale=0.7] at (-0.8,7.5) {$i'\!=\!0$}; 40 | \node[scale=0.7] at (-0.8,6.5) {$i'\!=\!1$}; 41 | \node[scale=0.7] at (0.5,8.5) {$j'\!=\!0$}; 42 | \node[scale=0.7] at (1.5,8.5) {$j'\!=\!1$}; 43 | 44 | \end{scope} 45 | 46 | \end{tikzpicture} -------------------------------------------------------------------------------- /images/fig-images-2.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=0.8, every node/.style={scale=1}] 2 | 3 | \draw[ultra thick,gray] (0,0) rectangle ++(4,4); 4 | \draw[very thick,red!50] (0.05,3.5) rectangle ++(3.9,0.45); 5 | \draw[very thick,red!50] (0.05,3) rectangle ++(3.9,0.45); 6 | \draw[very thick,blue!50] (0.05,2.5) rectangle ++(3.9,0.45); 7 | \draw[very thick,blue!50] (0.05,2) rectangle ++(3.9,0.45); 8 | % \node[blue!50,scale=4] at (2,1) {\bf A}; 9 | % \node[blue!50,scale=4] at (6,1) {\bf B}; 10 | 11 | \draw [->,>=latex,red!20,ultra thick,line width=7] (5,1.5) -- ++(3,0) node[above,pos=0.35,red] {\bf stretch}; 12 | 13 | \draw[very thick,black!80] (0.35,3.85) -- ++(0,-0.7) -- ++(0.8,0.7) -- ++(0,-0.7)-- ++(0.8,0.7) -- ++(0,-0.7)-- ++(0.8,0.7) -- ++(0,-0.7)-- ++(0.8,0.7) -- ++(0,-0.7) ; 14 | 15 | % \draw [blue] plot [smooth] coordinates {(6,0) (8,-1) (3,1) (1,0) (2,-1)}; 16 | \draw [->,ultra thick,red!50] 17 | (4.1,3.5) to[bend left=20] 18 | (8.8,2.75); 19 | \draw [->,ultra thick,blue!50] 20 | (4.1,2.5) to[bend left=15] 21 | (8.8,2.25); 22 | \begin{scope}[xshift=9cm, yshift=1cm] 23 | \draw[ultra thick,gray] (0,0) rectangle ++(8,2); 24 | \draw[very thick,red!50] (0.05,1.50) rectangle ++(7.9,0.45); 25 | \draw[very thick,blue!50] (0.05,1) rectangle ++(7.9,0.45); 26 | \end{scope} 27 | 28 | \end{tikzpicture} -------------------------------------------------------------------------------- /images/fig-images-2bis.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=0.8, every node/.style={scale=1}] 2 | 3 | 4 | \draw[very thick,red!50] (0,0) rectangle ++(4,1); 5 | \draw[very thick,red!50] (0,1) rectangle ++(4,1); 6 | 7 | \draw[very thick,black!20] (0.35,1.5) -- ++(0,-1) -- ++(0.8,1) -- ++(0,-1)-- ++(0.8,1) -- ++(0,-1)-- ++(0.8,1) -- ++(0,-1)-- ++(0.8,1) -- ++(0,-1) ; 8 | 9 | \node[blue!80,scale=1] at (0.3,1.5) {\bf A}; 10 | \node[blue!80,scale=1] at (0.4,0.45) {\bf a}; 11 | \node[blue!80,scale=1] at (1.2,1.5) {\bf B}; 12 | \node[blue!80,scale=1] at (1.2,0.5) {\bf b}; 13 | 14 | 15 | % \draw [->,>=latex,red!20,ultra thick,line width=7] (5,-0.5) -- ++(3,0) node[above,pos=0.35] {\bf \'etirer}; 16 | 17 | 18 | 19 | % \draw [blue] plot [smooth] coordinates {(6,0) (8,-1) (3,1) (1,0) (2,-1)}; 20 | \draw [->,ultra thick,red!50] 21 | (4.2,1) to[bend left=20] 22 | (7.8,1); 23 | 24 | \begin{scope}[xshift=8cm, yshift=0.5cm] 25 | 26 | \draw[very thick,red!50] (0,0) rectangle ++(8,1); 27 | \node[blue!80,scale=1] at (0.3,0.5) {\bf A}; 28 | \node[blue!80,scale=1] at (1.2,0.45) {\bf a}; 29 | \node[blue!80,scale=1] at (2.1,0.5) {\bf B}; 30 | \node[blue!80,scale=1] at (3,0.5) {\bf b}; 31 | \end{scope} 32 | 33 | \end{tikzpicture} -------------------------------------------------------------------------------- /images/fig-images-3.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=0.8, every node/.style={scale=1}] 2 | 3 | \draw[ultra thick,gray] (0,0) rectangle ++(4,2); 4 | \draw[ultra thick,gray] (4,0) rectangle ++(4,2); 5 | 6 | \node[blue!50,scale=4] at (2,1) {\bf A}; 7 | \node[blue!50,scale=4] at (6,1) {\bf B}; 8 | 9 | \draw [->,>=latex,red!20,ultra thick,line width=7] (9,1) -- ++(3,0) node[above,pos=0.35,red] {\bf fold}; 10 | 11 | % \draw [blue] plot [smooth] coordinates {(6,0) (8,-1) (3,1) (1,0) (2,-1)}; 12 | \draw [->,ultra thick,blue] 13 | (6,-0.2) to[out=-90,in=180] 14 | (8,-2) to[out=0,in=-90] 15 | ++(1,1.5) to[out=90,in=180] 16 | (8,-1.5) to[out=0,in=180] 17 | (12.8,0); 18 | 19 | \begin{scope}[xshift=13cm, yshift=1cm] 20 | \draw[ultra thick,gray] (0,0) rectangle ++(4,2); 21 | \draw[ultra thick,gray] (0,-2) rectangle ++(4,2); 22 | 23 | \node[blue!50,scale=4] at (2,1) {\bf A}; 24 | \node[blue!50,scale=4,rotate=180] at (2,-1) {\bf B}; 25 | \end{scope} 26 | 27 | \end{tikzpicture} -------------------------------------------------------------------------------- /images/gimp_to_pgm.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Conversion of Gimp pgm format 4 | # to our basic pgm format 5 | ############################## 6 | 7 | import os 8 | 9 | def gimp_to_pgm(filename): 10 | 11 | # File to read 12 | fic_in = open("input/"+filename+".pgm","r") 13 | 14 | # File to write 15 | name, extension = os.path.splitext(filename) 16 | new_name = "input/"+name + "_new"+".pgm" 17 | fic_out = open(new_name,"w") 18 | 19 | 20 | i = 0 # Line number 21 | j = 0 # Column number 22 | 23 | new_line = "" 24 | 25 | for line in fic_in: 26 | if i == 0: 27 | fic_out.write("P2\n") # Grayscale image 28 | 29 | elif i == 1: 30 | pass 31 | # Don't keep comments 32 | elif i == 2: # Keep rpws/columns 33 | list_line = line.split() 34 | nb_col = int(list_line[0]) 35 | nb_lig = int(list_line[1]) 36 | fic_out.write(line) 37 | 38 | elif i == 3: # Keep levels 39 | fic_out.write(line) 40 | 41 | else: 42 | line = line.split()[0] 43 | 44 | new_line = new_line + line + " " 45 | 46 | j = j + 1 47 | 48 | if j == nb_col: 49 | new_line = new_line + "\n" 50 | fic_out.write(new_line) 51 | new_line = "" 52 | j = 0 53 | i = i + 1 54 | 55 | # Close files 56 | fic_in.close() 57 | fic_out.close() 58 | return 59 | 60 | ################################## 61 | 62 | # gimp_to_pgm("pi_gimp") 63 | # gimp_to_pgm("chat_gimp") 64 | # gimp_to_pgm("reveil_gimp") 65 | gimp_to_pgm("surf_gimp") -------------------------------------------------------------------------------- /images/images.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images.pdf -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_0.png -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_1.png -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_2.png -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_3.png -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_4.png -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_5.png -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_6.png -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_7.png -------------------------------------------------------------------------------- /images/images_chapter/cat_gimp_new_photo_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/cat_gimp_new_photo_8.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_0.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_1.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_15.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_16.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_17.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_2.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_3.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_4.png -------------------------------------------------------------------------------- /images/images_chapter/clock_gimp_new_baker_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/clock_gimp_new_baker_5.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_0.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_1.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_2.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_3.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_4.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_5.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_6.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_7.png -------------------------------------------------------------------------------- /images/images_chapter/pi_gimp_new_photo_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/pi_gimp_new_photo_8.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_0.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_1.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_12.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_13.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_14.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_15.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_2.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_3.png -------------------------------------------------------------------------------- /images/images_chapter/surf_gimp_new_baker_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/images_chapter/surf_gimp_new_baker_4.png -------------------------------------------------------------------------------- /images/input/cat_original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/input/cat_original.jpg -------------------------------------------------------------------------------- /images/input/clock-original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/input/clock-original.jpg -------------------------------------------------------------------------------- /images/input/ecran-test-pgm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/input/ecran-test-pgm.png -------------------------------------------------------------------------------- /images/input/pi-original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/input/pi-original.jpg -------------------------------------------------------------------------------- /images/input/surf-original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/images/input/surf-original.png -------------------------------------------------------------------------------- /images/input/test.pgm: -------------------------------------------------------------------------------- 1 | P2 2 | 5 5 3 | 255 4 | 128 192 128 192 128 5 | 224 0 228 0 224 6 | 228 228 228 228 228 7 | 224 64 64 64 224 8 | 192 192 192 192 192 9 | -------------------------------------------------------------------------------- /images/output/test.pgm: -------------------------------------------------------------------------------- 1 | P2 2 | 5 5 3 | 255 4 | 128 192 128 192 128 5 | 224 0 228 0 224 6 | 228 228 228 228 228 7 | 224 64 64 64 224 8 | 192 192 192 192 192 9 | -------------------------------------------------------------------------------- /life/fig-life-0a.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | 5 | % Jeu de la vie - Naissance 6 | \fill[red] (2,1) rectangle ++(1,1); 7 | \fill[red] (2,2) rectangle ++(1,1); 8 | \fill[red] (1,2) rectangle ++(1,1); 9 | 10 | \draw (0,0) grid ++(4,4); 11 | 12 | \node at (2,-0.7) {\bf Initial position (day $j$)}; 13 | 14 | 15 | % Jeu de la vie - Voisin 16 | \begin{scope}[xshift=9cm] 17 | \fill[red] (2,1) rectangle ++(1,1); 18 | \fill[red] (2,2) rectangle ++(1,1); 19 | \fill[red] (1,2) rectangle ++(1,1); 20 | 21 | \fill[green!20] (1,1) rectangle ++(1,1); 22 | 23 | \draw (0,0) grid ++(4,4); 24 | 25 | \draw[<-,>=latex,ultra thick] (1.5,1.5) to[bend left] (3,4.5) node[right] {Has $3$ neighbors}; 26 | 27 | 28 | \node at (2,-0.7) {\bf Number of neighbors}; 29 | \end{scope} 30 | 31 | % Jeu de la vie - Evolution 32 | \begin{scope}[xshift=18cm] 33 | \fill[red] (2,1) rectangle ++(1,1); 34 | \fill[red] (2,2) rectangle ++(1,1); 35 | \fill[red] (1,2) rectangle ++(1,1); 36 | 37 | \fill[red] (1,1) rectangle ++(1,1); 38 | 39 | \draw (0,0) grid ++(4,4); 40 | 41 | \draw[<-,>=latex,ultra thick] (1.5,1.5) to[bend left] (3,4.5) node[right] {Birth}; 42 | 43 | 44 | \node at (2,-0.7) {\bf Evolution (day $j+1$)}; 45 | \end{scope} 46 | 47 | \draw[->,>=latex,ultra thick, blue] (4,-1.5) to[bend right=20] node[midway, below] {\bf Birth} (16,-1.5) ; 48 | 49 | \end{tikzpicture} -------------------------------------------------------------------------------- /life/fig-life-0c.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | 5 | % Jeu de la vie - Mort 6 | 7 | \fill[red] (1,2) rectangle ++(1,1); 8 | \fill[red] (2,2) rectangle ++(1,1); 9 | \fill[red] (3,2) rectangle ++(1,1); 10 | 11 | \draw (0,0) grid ++(5,5); 12 | 13 | 14 | \node at (2.5,-0.7) {\bf Initial position (day $j$)}; 15 | 16 | 17 | % Jeu de la vie - Voisin 18 | \begin{scope}[xshift=8cm] 19 | 20 | 21 | \fill[red] (1,2) rectangle ++(1,1); 22 | \fill[red] (2,2) rectangle ++(1,1); 23 | \fill[red] (3,2) rectangle ++(1,1); 24 | 25 | \draw (0,0) grid ++(5,5); 26 | 27 | \foreach \i in {0.5,1.5,2.5,3.5,4.5}{ 28 | \node[darkgray] at (\i,0.5) {\bf 0}; 29 | \node[darkgray] at (\i,4.5) {\bf 0}; 30 | } 31 | \foreach \j in {1.5,2.5,3.5}{ 32 | \node[darkgray] at (0.5,\j) {\bf 1}; 33 | \node[darkgray] at (4.5,\j) {\bf 1}; 34 | } 35 | 36 | \node[white] at (1.5,2.5) {\bf 1}; 37 | \node[white] at (3.5,2.5) {\bf 1}; 38 | \node[darkgray] at (1.5,1.5) {\bf 2}; 39 | \node[darkgray] at (3.5,1.5) {\bf 2}; 40 | \node[darkgray] at (1.5,3.5) {\bf 2}; 41 | \node[darkgray] at (3.5,3.5) {\bf 2}; 42 | \node[white] at (2.5,2.5) {\bf 2}; 43 | 44 | \node[darkgray] at (2.5,3.5) {\bf 3}; 45 | \node[darkgray] at (2.5,1.5) {\bf 3}; 46 | 47 | 48 | \node at (2.5,-0.7) {\bf Numbers of neighbors}; 49 | \end{scope} 50 | 51 | % Jeu de la vie - Evolution 52 | \begin{scope}[xshift=16cm] 53 | 54 | \fill[red] (2,1) rectangle ++(1,1); 55 | \fill[red] (2,2) rectangle ++(1,1); 56 | \fill[red] (2,3) rectangle ++(1,1); 57 | 58 | \draw (0,0) grid ++(5,5); 59 | 60 | \node at (2.5,-0.7) {\bf Evolution (day $j+1$)}; 61 | \end{scope} 62 | 63 | \end{tikzpicture} -------------------------------------------------------------------------------- /life/fig-life-1.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | % Jeu de la vie - Bouche 5 | \fill[red] (1,1) rectangle ++(1,1); 6 | \fill[red] (2,1) rectangle ++(1,1); 7 | \fill[red] (3,1) rectangle ++(1,1); 8 | \fill[red] (2,2) rectangle ++(1,1); 9 | \fill[red] (3,2) rectangle ++(1,1); 10 | \fill[red] (4,2) rectangle ++(1,1); 11 | 12 | \draw (0,0) grid ++(6,4); 13 | 14 | \node at (3,-1.5) {\bf Cells}; 15 | 16 | % Jeu de la vie - Tableau 17 | \begin{scope}[xshift=12cm] 18 | \draw (0,0) grid ++(6,4); 19 | 20 | \foreach \i in {0.5,1.5,2.5,3.5,4.5,5.5}{ 21 | \node[blue] at (\i,0.5) {\bf 0}; 22 | \node[blue] at (\i,3.5) {\bf 0}; 23 | } 24 | 25 | 26 | \node[blue] at (0.5,1.5) {\bf 0}; 27 | \node[blue] at (1.5,1.5) {\bf 1}; 28 | \node[blue] at (2.5,1.5) {\bf 1}; 29 | \node[blue] at (3.5,1.5) {\bf 1}; 30 | \node[blue] at (4.5,1.5) {\bf 0}; 31 | \node[blue] at (5.5,1.5) {\bf 0}; 32 | 33 | \node[blue] at (0.5,2.5) {\bf 0}; 34 | \node[blue] at (1.5,2.5) {\bf 0}; 35 | \node[blue] at (2.5,2.5) {\bf 1}; 36 | \node[blue] at (3.5,2.5) {\bf 1}; 37 | \node[blue] at (4.5,2.5) {\bf 1}; 38 | \node[blue] at (5.5,2.5) {\bf 0}; 39 | 40 | \node at (3,-1.5) {\bf Array}; 41 | 42 | \draw[->,>=latex,very thick] (0,5) to node[midway, above] {index $j$} ++(6,0) ; 43 | \draw[->,>=latex,very thick] (-2,4) to node[midway, left] {index $i$} ++(0,-4) ; 44 | 45 | \node[scale=0.7,above] at (0.5,4) {$j=0$}; 46 | \node[scale=0.7,above] at (1.5,4) {$j=1$}; 47 | \node[scale=0.7,above] at (3.5,4.05) {$\cdots$}; 48 | \node[scale=0.7,above] at (5.5,4) {$j=p-1$}; 49 | 50 | \node[scale=0.7,left] at (0,3.5) {$i=0$}; 51 | \node[scale=0.7,left] at (0,2.5) {$i=1$}; 52 | \node[scale=0.7,left] at (-0.3,1.5) {$\vdots$}; 53 | \node[scale=0.7,left] at (0,0.5) {$i=n-1$}; 54 | 55 | 56 | \draw[<->,>=latex,very thick,gray] (0,-0.5) to node[midway, below] {$p$} ++(6,0) ; 57 | \draw[<->,>=latex,very thick,gray] (6.5,0) to node[midway, right] {$n$} ++(0,4) ; 58 | 59 | \end{scope} 60 | 61 | \end{tikzpicture} -------------------------------------------------------------------------------- /life/fig-life-4a.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | % Jeu de la vie - Carré 5 | \fill[red] (1,1) rectangle ++(1,1); 6 | \fill[red] (2,1) rectangle ++(1,1); 7 | \fill[red] (1,2) rectangle ++(1,1); 8 | \fill[red] (2,2) rectangle ++(1,1); 9 | 10 | \draw (0,0) grid ++(4,4); 11 | 12 | \node at (2,-0.5) {\bf Square}; 13 | 14 | \begin{scope}[xshift=5cm] 15 | % Jeu de la vie - Vaisseau 16 | \fill[red] (1,1) rectangle ++(1,1); 17 | \fill[red] (2,1) rectangle ++(1,1); 18 | \fill[red] (3,1) rectangle ++(1,1); 19 | \fill[red] (3,2) rectangle ++(1,1); 20 | \fill[red] (2,3) rectangle ++(1,1); 21 | 22 | \draw (0,0) grid ++(5,5); 23 | 24 | \node at (2.5,-0.5) {\bf Spaceship}; 25 | \end{scope} 26 | 27 | 28 | \end{tikzpicture} -------------------------------------------------------------------------------- /life/fig-life-4b.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | % Jeu de la vie - Pulsar 5 | \def\motif{ 6 | \fill[red] (3,1) rectangle ++(1,1); 7 | \fill[red] (4,1) rectangle ++(1,1); 8 | \fill[red] (5,1) rectangle ++(1,1); 9 | 10 | \fill[red] (3,6) rectangle ++(1,1); 11 | \fill[red] (4,6) rectangle ++(1,1); 12 | \fill[red] (5,6) rectangle ++(1,1); 13 | 14 | \fill[red] (1,3) rectangle ++(1,1); 15 | \fill[red] (1,4) rectangle ++(1,1); 16 | \fill[red] (1,5) rectangle ++(1,1); 17 | 18 | \fill[red] (6,3) rectangle ++(1,1); 19 | \fill[red] (6,4) rectangle ++(1,1); 20 | \fill[red] (6,5) rectangle ++(1,1); 21 | 22 | } 23 | 24 | \begin{scope}[scale=0.5] 25 | \motif; 26 | 27 | \begin{scope}[xshift=15cm,rotate=90] 28 | \motif; 29 | \end{scope} 30 | 31 | \begin{scope}[yshift=15cm,rotate=-90] 32 | \motif; 33 | \end{scope} 34 | 35 | \begin{scope}[yshift=15cm,xshift=15cm,rotate=180] 36 | \motif; 37 | \end{scope} 38 | 39 | \draw (0,0) grid ++(15,15); 40 | 41 | \node at (7.5,-1) {\bf Pulsar}; 42 | \end{scope} 43 | 44 | 45 | 46 | 47 | 48 | 49 | \end{tikzpicture} -------------------------------------------------------------------------------- /life/life-tkinter-mouse.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Game of life 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Click of mouse 9 | ############################## 10 | 11 | 12 | from tkinter import * 13 | 14 | # Window 15 | root = Tk() 16 | canvas = Canvas(root, width=800, height=600, background="white") 17 | canvas.pack(side=LEFT, padx=5, pady=5) 18 | 19 | # Catch mouse click 20 | def action_mouse_click(event): 21 | canvas.focus_set() 22 | x = event.x 23 | y = event.y 24 | canvas.create_rectangle(x,y,x+10,y+10,fill="red") 25 | print("Click at x =",x,", y =",y) 26 | return 27 | 28 | # Association click/action 29 | canvas.bind("", action_mouse_click) 30 | 31 | # Launch 32 | root.mainloop() 33 | 34 | -------------------------------------------------------------------------------- /life/life.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/life/life.pdf -------------------------------------------------------------------------------- /life/life_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Game of life 4 | ############################## 5 | 6 | ############################## 7 | # Activity 1 - Array 8 | ############################## 9 | 10 | 11 | ################################################## 12 | ## Question 1 ## 13 | 14 | n, p = 5, 8; 15 | array = [[0 for j in range(p)] for i in range(n)] 16 | 17 | # Blinker 18 | array[2][2] = 1 19 | array[2][3] = 1 20 | array[2][4] = 1 21 | 22 | 23 | ################################################## 24 | ## Question 2 ## 25 | 26 | def print_array(array): 27 | """ Print an array on the screen 28 | Input: a two dimensional arrayle 29 | Output: nothing (display on screen) """ 30 | 31 | for i in range(n): 32 | for j in range(p): 33 | print(array[i][j], end="") 34 | print() 35 | 36 | return 37 | 38 | 39 | # Test 40 | print_array(array) 41 | 42 | -------------------------------------------------------------------------------- /life/screen-life-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/life/screen-life-0.png -------------------------------------------------------------------------------- /life/screen-life-2-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/life/screen-life-2-en.png -------------------------------------------------------------------------------- /life/screen-life-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/life/screen-life-2.png -------------------------------------------------------------------------------- /life/screen-life-4a-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/life/screen-life-4a-en.png -------------------------------------------------------------------------------- /life/screen-life-4a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/life/screen-life-4a.png -------------------------------------------------------------------------------- /life/screen-life-4b-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/life/screen-life-4b-en.png -------------------------------------------------------------------------------- /life/screen-life-4b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/life/screen-life-4b.png -------------------------------------------------------------------------------- /lists/fig-lists-1.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[thick,scale=1.7, every node/.style={scale=1}] 2 | 3 | \draw (0,0) grid ++(6,1); 4 | 5 | \node at (0.5,0.5) {\bf "A"}; 6 | \node at (1.5,0.5) {\bf "B"}; 7 | \node at (2.5,0.5) {\bf "C"}; 8 | \node at (3.5,0.5) {\bf "D"}; 9 | \node at (4.5,0.5) {\bf "E"}; 10 | \node at (5.5,0.5) {\bf "F"}; 11 | 12 | \node at (-0.9,-0.47) {rank : }; 13 | \node at (0.5,-0.5) {0}; 14 | \node at (1.5,-0.5) {1}; 15 | \node at (2.5,-0.5) {2}; 16 | \node at (3.5,-0.5) {3}; 17 | \node at (4.5,-0.5) {4}; 18 | \node at (5.5,-0.5) {5}; 19 | 20 | 21 | 22 | \end{tikzpicture} -------------------------------------------------------------------------------- /lists/fig-lists-2.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[thick,scale=1.2, every node/.style={scale=1.2}] 2 | 3 | 4 | 5 | \draw (0,0) grid ++(6,1); 6 | 7 | \node at (0.5,0.5) {\bf }; 8 | \node at (1.5,0.5) {\bf }; 9 | \node at (2.5,0.5) {\bf }; 10 | \node at (3.5,0.5) {\bf 9}; 11 | \node at (4.5,0.5) {\bf 7}; 12 | \node at (5.5,0.5) {\bf }; 13 | 14 | \node[blue,right] at (6.5,0.5) {\bf before}; 15 | 16 | \draw[<->,>=latex,blue,ultra thick] (3.4,-0.2) to[bend right] ++(1.2,0); 17 | 18 | \begin{scope}[yshift=-2cm] 19 | \draw (0,0) grid ++(6,1); 20 | 21 | \node at (0.5,0.5) {\bf }; 22 | \node at (1.5,0.5) {\bf }; 23 | \node at (2.5,0.5) {\bf }; 24 | \node at (3.5,0.5) {\bf 7}; 25 | \node at (4.5,0.5) {\bf 9}; 26 | \node at (5.5,0.5) {\bf }; 27 | 28 | \node[blue,right] at (6.5,0.5) {\bf after}; 29 | 30 | \end{scope} 31 | 32 | 33 | 34 | \end{tikzpicture} -------------------------------------------------------------------------------- /lists/fig-lists-3.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[thick,scale=1.7, every node/.style={scale=1}] 2 | 3 | \draw (0,0) grid ++(7,1); 4 | 5 | \node at (0.5,0.5) {\bf "A"}; 6 | \node at (1.5,0.5) {\bf "B"}; 7 | \node at (2.5,0.5) {\bf "C"}; 8 | \node at (3.5,0.5) {\bf "D"}; 9 | \node at (4.5,0.5) {\bf "E"}; 10 | \node at (5.5,0.5) {\bf "F"}; 11 | \node at (6.5,0.5) {\bf "G"}; 12 | 13 | \node at (-0.9,-0.47) {rank : }; 14 | \node at (0.5,-0.5) {0}; 15 | \node at (1.5,-0.5) {1}; 16 | \node at (2.5,-0.5) {2}; 17 | \node at (3.5,-0.5) {3}; 18 | \node at (4.5,-0.5) {4}; 19 | \node at (5.5,-0.5) {5}; 20 | \node at (6.5,-0.5) {6}; 21 | 22 | 23 | \end{tikzpicture} -------------------------------------------------------------------------------- /lists/fig-lists-4.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[thick,scale=1, every node/.style={scale=1.2}] 2 | 3 | \draw (0,0) grid ++(9,1); 4 | 5 | [7,2,4,5,3,10,9,8,3] 6 | \node at (0.5,0.5) {\bf 7}; 7 | \node at (1.5,0.5) {\bf 2}; 8 | \node at (2.5,0.5) {\bf 4}; 9 | \node at (3.5,0.5) {\bf 5}; 10 | \node at (4.5,0.5) {\bf 3}; 11 | \node at (5.5,0.5) {\bf 10}; 12 | \node at (6.5,0.5) {\bf 9}; 13 | \node at (7.5,0.5) {\bf 8}; 14 | \node at (8.5,0.5) {\bf 3}; 15 | 16 | 17 | \node at (-0.5,-0.45) {rank : }; 18 | \node at (0.5,-0.5) {0}; 19 | \node at (1.5,-0.5) {1}; 20 | \node at (2.5,-0.5) {2}; 21 | \node at (3.5,-0.5) {3}; 22 | \node at (4.5,-0.5) {4}; 23 | \node at (5.5,-0.5) {5}; 24 | \node at (6.5,-0.5) {6}; 25 | \node at (7.5,-0.5) {7}; 26 | \node at (8.5,-0.5) {8}; 27 | 28 | \end{tikzpicture} -------------------------------------------------------------------------------- /lists/fig-lists-I-tir.tikz: -------------------------------------------------------------------------------- 1 | 2 | \begin{tikzpicture}[scale=1.5] 3 | 4 | \draw[->,>=latex, gray] (-0.5,0)--(6,0) node[below,black] {$x$}; 5 | \draw[->,>=latex, gray] (0,-0.5)--(0,4.5) node[right,black] {$y$}; 6 | 7 | \def\v0{10} 8 | \def\g{9.8} 9 | \def\angle{60} 10 | 11 | \draw[ultra thick, color=blue,domain=0:1,smooth] plot ( {\x*\v0*cos(\angle)} , {-1/2*\g*\x^2+\x*\v0*sin(\angle)}); 12 | 13 | \coordinate (M) at (3,3.45); 14 | \draw[dashed] (M)--(3,0) node[below] {$x$}; 15 | \draw[dashed] (M)--(0,3.45) node[left] {$y(x)$}; 16 | 17 | \fill (M) circle (2pt); 18 | 19 | \draw[->,>=latex,thick, red] (0,0)--++(62:2) node[midway,left] {$v$}; 20 | \draw[red, double] (1.1,0) arc (0:62:1.1) node[midway, right] {$\alpha$}; 21 | 22 | % \draw[->,>=latex,very thick] (0,0)--++(1,0) node[midway, below] {$\vec {i}$}; 23 | % \draw[->,>=latex,very thick] (0,0)--++(0,1) node[midway, left] {$\vec {j}$}; 24 | 25 | \fill (0,0) circle (2pt); 26 | \node[below left] at (0,0) {$(0,0)$}; 27 | \end{tikzpicture} 28 | -------------------------------------------------------------------------------- /lists/lists-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lists/lists-1.pdf -------------------------------------------------------------------------------- /lists/lists-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lists/lists-2.pdf -------------------------------------------------------------------------------- /lists/lists_II_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Lists II 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 1 - List comprehension 9 | ############################## 10 | 11 | 12 | ## Question 1 ## 13 | 14 | ############################## 15 | def multiplication(list,k): 16 | return [k*x for x in list] 17 | 18 | 19 | ## Question 2 ## 20 | 21 | ############################## 22 | def power(list,k): 23 | return [x**k for x in list] 24 | 25 | 26 | ## Question 3 ## 27 | 28 | ############################## 29 | def addition(list1,list2): 30 | list_add = [] 31 | for i in range(len(list1)): 32 | list_add.append(list1[i]+list2[i]) 33 | return list_add 34 | 35 | 36 | ## Question 4 ## 37 | 38 | ############################## 39 | def non_zero(list): 40 | return [x for x in list if x != 0] 41 | 42 | 43 | ## Question 5 ## 44 | 45 | ############################## 46 | def even(list): 47 | return [x for x in list if x % 2 == 0] 48 | 49 | 50 | # Test 51 | print("--- Multiplication ---") 52 | print(multiplication([1,2,3,4,5],2)) 53 | print("--- Power ---") 54 | print(power([1,2,3,4,5],3)) 55 | print("--- Addition ---") 56 | print(addition([1,2,3],[4,5,6])) 57 | print("--- Without zeros ---") 58 | print(non_zero([1,0,2,3,0,4,5,0])) 59 | print("--- Pairs ---") 60 | print(even([1,0,2,3,0,4,5,0])) 61 | 62 | 63 | -------------------------------------------------------------------------------- /lists/lists_II_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Lists II 4 | ############################## 5 | 6 | ############################## 7 | # Activity 3 - Array 8 | ############################## 9 | 10 | 11 | ## Question 1 ## 12 | 13 | ############################## 14 | def sum_diagonal(array): 15 | n = len(array) 16 | S = 0 17 | for i in range(n): 18 | S = S + array[i][i] 19 | return S 20 | 21 | 22 | ## Question 2 ## 23 | 24 | ############################## 25 | def sum_antidiagonal(array): 26 | n = len(array) 27 | S = 0 28 | for i in range(n): 29 | S = S + array[n-1-i][i] 30 | return S 31 | 32 | 33 | ## Question 3 ## 34 | 35 | ############################## 36 | def sum_all(array): 37 | n = len(array) 38 | S = 0 39 | for i in range(n): 40 | for j in range(n): 41 | S = S + array[i][i] 42 | return S 43 | 44 | 45 | ## Question 4 ## 46 | 47 | ############################## 48 | def print_array(array): 49 | """ 50 | Print a square on screen 51 | Input: an array of size n x n 52 | Output: nothing (display on terminal) 53 | """ 54 | 55 | n = len(array) 56 | for i in range(n): 57 | for j in range(n): 58 | print('{:>3d}'.format(array[i][j]),end="") 59 | print() 60 | return 61 | 62 | 63 | 64 | 65 | ############################## 66 | array = [ [1,2,3], [4,5,6], [7,8,9] ] 67 | 68 | print("--- Sum diagonale---") 69 | print(sum_diagonal(array)) 70 | 71 | print("--- Sum anti-diagonal ---") 72 | print(sum_antidiagonal(array)) 73 | 74 | print("--- Sum all ---") 75 | print(sum_all(array)) 76 | 77 | print("--- Display ---") 78 | print_array(array) 79 | 80 | -------------------------------------------------------------------------------- /lists/lists_II_lesson.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Lists II - Cours 4 | ############################## 5 | 6 | ############################## 7 | # C1 - Trancher de listes 8 | 9 | maliste = [7,2,4,5,3,10,9,8,] 10 | print(maliste[3:5]) 11 | print(maliste[3:]) 12 | print(maliste[:6]) 13 | print(maliste[-1]) 14 | #print(maliste[::2]) 15 | 16 | 17 | ############################## 18 | # C2 - Liste par compréhension 19 | 20 | maliste = [1,2,3,4,5,6,7,6,5,4,3,2,1] 21 | liste_doubles = [ 2*x for x in maliste ] 22 | liste_carres = [ x**2 for x in maliste ] 23 | liste_partielle = [x for x in maliste if x > 2] 24 | 25 | print(liste_doubles) 26 | print(liste_carres) 27 | print(liste_partielle) 28 | 29 | 30 | ############################## 31 | # C3 - Liste de listes 32 | 33 | array = [ [2,14,5], [3,5,7], [15,19,4], [8,6,5] ] 34 | print(array[0]) 35 | print(array[1]) 36 | print(array[0][0]) 37 | print(array[0][1]) 38 | print(array[2][1]) 39 | 40 | 41 | -------------------------------------------------------------------------------- /lists/lists_I_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Lists I 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Cours 1 9 | 10 | mylist = [11,13,17,19] 11 | mylist.append(23) 12 | mylist.append(29) 13 | print(mylist[5]) 14 | len(mylist) 15 | 16 | 17 | ############################## 18 | # Activity 1 - Interst 19 | ############################## 20 | 21 | ## Question 1 ## 22 | 23 | ############################## 24 | def simple_interests(S0,p,n): 25 | mylist = [S0] 26 | interest = S0 * p/100 27 | S = S0 28 | for i in range(n): 29 | S = S + interest 30 | mylist.append(S) 31 | return mylist 32 | 33 | 34 | # Test 35 | print("--- Simple interests ---") 36 | list_simple_interests = simple_interests(1000,10,12) 37 | print(list_simple_interests) 38 | print(list_simple_interests[11]) 39 | 40 | 41 | 42 | ## Question 2 ## 43 | 44 | ############################## 45 | def compound_interests(S0,p,n): 46 | mylist = [S0] 47 | S = S0 48 | for i in range(n): 49 | interest = S * p/100 50 | S = S + interest 51 | mylist.append(S) 52 | return mylist 53 | 54 | 55 | # Test 56 | print("--- Compound interests ---") 57 | list_compound_interests = compound_interests(1000,7,12) 58 | print(list_compound_interests) 59 | print(list_compound_interests[11]) 60 | 61 | -------------------------------------------------------------------------------- /lists/lists_I_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Lists I 4 | ############################## 5 | 6 | ############################## 7 | # Activity 3 - Bubble sort 8 | ############################## 9 | 10 | def bubble_sort(thelist): 11 | 12 | newlist = list(thelist) 13 | 14 | n = len(newlist) 15 | 16 | for i in range(n-1,-1,-1): 17 | for j in range(i): 18 | if newlist[j+1] < newlist[j]: 19 | el = newlist[j] 20 | newlist[j] = newlist[j+1] 21 | newlist[j+1] = el 22 | 23 | return newlist 24 | 25 | # Test 26 | print("--- Bubble sort ---") 27 | print(bubble_sort([13,11,7,4,6,8,12,6])) 28 | 29 | thelist = [13,11,7,4,6,8,12,6] 30 | newlist = bubble_sort(thelist) 31 | print(thelist) 32 | print(newlist) 33 | 34 | 35 | print(sorted([13,11,7,4,6,8,12,6])) 36 | 37 | thelist = [13,11,7,4,6,8,12,6] 38 | thelist.sort() 39 | print(thelist) 40 | -------------------------------------------------------------------------------- /lists/lists_I_4.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Lists I 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 4 - Arithmetic 9 | ############################## 10 | 11 | ## Question 1 ## 12 | 13 | ############################## 14 | def prime_factors(n): 15 | thelist = [] 16 | d = 2 17 | while d <= n: 18 | if n%d == 0: 19 | thelist = thelist + [d] 20 | n = n // d 21 | else: 22 | d = d + 1 23 | # if len(thelist)==0: # Case of a prime number 24 | # thelist = [n] 25 | return thelist 26 | 27 | 28 | # Test 29 | print("--- Prime factors ---") 30 | n = 2*2*2*3*7*7*11 31 | print(n) 32 | print(prime_factors(2*2*2*3*7*7*11)) 33 | 34 | 35 | ## Question 2 ## 36 | 37 | ############################## 38 | def list_primes(n): 39 | thelist = list(range(2,n)) 40 | for d in range(2,n): 41 | for k in thelist: 42 | if k%d == 0 and k != d: 43 | thelist.remove(k) 44 | return thelist 45 | 46 | print("--- List of primes numbers ---") 47 | print(list_primes(100)) 48 | 49 | -------------------------------------------------------------------------------- /lists/lists_I_5.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Lists I 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 5 - Balistics 9 | ############################## 10 | 11 | import matplotlib.pyplot as plt 12 | from math import * 13 | 14 | def parabolic_shot(x,v,alpha): 15 | g = 9.81 16 | alpha = 2*pi/360*alpha # angle in radians 17 | y = -1/2 * g / (v * cos(alpha))**2 * x**2 + tan(alpha) * x 18 | return y 19 | 20 | def list_abscissa(xmax,n): 21 | list_x = [] 22 | for i in range(n+1): 23 | x = i * xmax/n 24 | list_x.append(x) 25 | return list_x 26 | 27 | def list_trajectory(xmax,n,v,alpha): 28 | list_y = [] 29 | for i in range(n+1): 30 | x = i * xmax/n 31 | y = parabolic_shot(x,v,alpha) 32 | list_y.append(y) 33 | return list_y 34 | 35 | list_x = list_abscissa(270,100) 36 | tir30 = list_trajectory(270,100,50,30) 37 | tir45 = list_trajectory(270,100,50,45) 38 | tir60 = list_trajectory(270,100,50,60) 39 | plt.plot(list_x,tir30,color="blue") 40 | plt.plot(list_x,tir45,color="red") 41 | plt.plot(list_x,tir60,color="green") 42 | plt.grid() 43 | plt.show() 44 | -------------------------------------------------------------------------------- /lists/lists_I_lesson.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Lists I 4 | ############################## 5 | 6 | ############################## 7 | # Lesson 1 - Construct a list 8 | 9 | list_squares = [] # Start from the empty list 10 | 11 | for i in range(10): 12 | list_squares.append(i**2) # Add one square 13 | 14 | print(list_squares) 15 | 16 | 17 | ############################## 18 | # Lesson 2 - Plot a list 19 | 20 | import matplotlib.pyplot as plt 21 | 22 | 23 | mylist1 = [3,5,9,8,0,3] 24 | mylist2 = [4,7,7,2,8,9] 25 | plt.plot(mylist1,color="red") 26 | plt.plot(mylist2,color="blue") 27 | plt.grid() 28 | plt.show() 29 | 30 | 31 | 32 | list_x = [2, 3, 5, 7, 9] 33 | list_y = [4, 9, 25, 49, 81] 34 | plt.plot(list_x,list_y,color="red") 35 | plt.grid() 36 | plt.show() 37 | 38 | -------------------------------------------------------------------------------- /lists/screen-lists-I-tir-bis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lists/screen-lists-I-tir-bis.png -------------------------------------------------------------------------------- /lists/screen-lists-I-tir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lists/screen-lists-I-tir.png -------------------------------------------------------------------------------- /lists/screen-lists-lesson-visualization-bis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lists/screen-lists-lesson-visualization-bis.png -------------------------------------------------------------------------------- /lists/screen-lists-lesson-visualization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lists/screen-lists-lesson-visualization.png -------------------------------------------------------------------------------- /lsystems/fig-brackets.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=1] 2 | 3 | 4 | 5 | \draw[ultra thick,blue] (0,0) -- ++(1,0) -- ++(0,1) ; 6 | 7 | \draw[ultra thick,red] (1,1) -- ++(-3,0); 8 | \draw[ultra thick,green!70!black] (1,1) -- ++(0,1); 9 | \draw[ultra thick,purple] (1,2) -- ++(2,0); 10 | \draw[ultra thick,orange] (1,2) -- ++(0,1); 11 | 12 | \node[scale=1.5,right] at (3.2,1) {\bf 13 | {\color{blue}AlA} 14 | {\color{red}[lAAA]} 15 | {\color{green!70!black}A} 16 | {\color{purple}[rAA]} 17 | {\color{orange}A}}; 18 | 19 | \fill (0,0) circle (2pt) node[below]{$O$}; 20 | \fill (1,1) circle (2pt) node[right]{$P$}; 21 | \fill (1,2) circle (2pt) node[left]{$Q$}; 22 | 23 | \draw[->,>=latex,thick] (1.05,1)-- ++(0,0.5); 24 | \draw[->,>=latex,thick] (1.05,2)-- ++(0,0.5); 25 | \end{tikzpicture} 26 | -------------------------------------------------------------------------------- /lsystems/fig-stacks.tikz: -------------------------------------------------------------------------------- 1 | 2 | \usetikzlibrary{patterns} 3 | 4 | \begin{tikzpicture}[scale=0.8] 5 | 6 | 7 | 8 | \draw[ultra thick] (-3,0) -- (3,0); 9 | \fill[pattern=north west lines] (-3,-1) rectangle (3,0); 10 | 11 | 12 | \draw[thick] (-2,0) rectangle ++(4,1); 13 | \node at (0,0.5) {$\big((0,0),30\big)$}; 14 | 15 | \draw[thick] (-2,1) rectangle ++(4,1); 16 | \node at (0,1.5) {$\big((0,0),90\big)$}; 17 | 18 | \draw[thick] (-2,2) rectangle ++(4,1); 19 | \node at (0,2.5) {$\big((100,100),0\big)$}; 20 | 21 | \draw[thick] (-2,3) rectangle ++(4,1); 22 | \node at (0,3.5) {$\big((0,0),0\big)$}; 23 | 24 | \draw[thick] (-2,4) rectangle ++(4,1); 25 | \node at (0,4.5) {$\big((-100,0),60\big)$}; 26 | 27 | 28 | \node at (0,-2) {\bf A stack}; 29 | 30 | \node[right] at (6.1,4) {Top of the stack}; 31 | \draw[->,>=latex,thick ] (6,4) to[bend right] (2,4.5); 32 | 33 | \end{tikzpicture} 34 | -------------------------------------------------------------------------------- /lsystems/lsystems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/lsystems.pdf -------------------------------------------------------------------------------- /lsystems/optional_argument.py: -------------------------------------------------------------------------------- 1 | 2 | def draw(length, width, color): 3 | ... 4 | 5 | draw(100, 5, "blue") 6 | 7 | 8 | 9 | def draw(length, width=5, color="blue") 10 | ... 11 | 12 | draw(100) 13 | 14 | draw(100, width=10) 15 | 16 | draw(100, color="red") 17 | 18 | draw(100, width=10, color="red") 19 | 20 | draw(100, 10, "red") 21 | 22 | draw(color="red", width=10, length=100) 23 | -------------------------------------------------------------------------------- /lsystems/pres-lsystems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/pres-lsystems.pdf -------------------------------------------------------------------------------- /lsystems/screen-lsystems-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-1.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-10.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-11.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-12.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-13.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-14.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-15.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-16.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-17.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-18.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-2.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-3a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-3a.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-3b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-3b.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-3c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-3c.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-3d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-3d.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-3e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-3e.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-4.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-5.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-6.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-7a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-7a.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-7b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-7b.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-7c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-7c.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-7d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-7d.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-7e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-7e.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-8.png -------------------------------------------------------------------------------- /lsystems/screen-lsystems-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/lsystems/screen-lsystems-9.png -------------------------------------------------------------------------------- /markdown/lesson_tkinter_text.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Text viewer - Markdown 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Lesson tkinter 9 | ############################## 10 | 11 | 12 | from tkinter import * 13 | from tkinter.font import Font 14 | 15 | # tkinter window 16 | root = Tk() 17 | 18 | canvas = Canvas(root, width=800, height=600, background="white") 19 | canvas.pack(fill="both", expand=True) 20 | 21 | # Font 22 | myfont = Font(family="Times", size=30) 23 | 24 | # Some text 25 | canvas.create_text(100,100, text="Text with Python!",anchor=SW,font=myfont,fill="blue") 26 | 27 | 28 | # Font 29 | myfont = Font(family="Courier", weight="bold",size=30) 30 | 31 | # Some text 32 | canvas.create_text(100,200, text="Bold text",anchor=SW,font=myfont,fill="black") 33 | 34 | 35 | # Font 36 | myfont = Font(family="Helvetica", slant="italic",size=30) 37 | 38 | # Some text 39 | canvas.create_text(100,300, text="Italic text",anchor=SW,font=myfont,fill="red") 40 | 41 | 42 | 43 | # Bounding box 44 | 45 | # Font 46 | myfont = Font(family="Courier", weight="bold",size=30) 47 | 48 | # Some text 49 | mytext = canvas.create_text(400,400, text="Text in a box",anchor=SW,font=myfont,fill="red") 50 | 51 | # Coordinates of the bounding rectangle (x1,y1,x2,y2) 52 | x1,y1,x2,y2 = canvas.bbox(mytext) 53 | 54 | # Display the bounding box 55 | canvas.create_rectangle(x1,y1,x2,y2,width=2) 56 | 57 | # Launch the window 58 | root.mainloop() 59 | -------------------------------------------------------------------------------- /markdown/markdown1.md: -------------------------------------------------------------------------------- 1 | # On the Origins of Species 2 | 3 | ## by Charles Darwin 4 | 5 | When on board H.M.S. * Beagle * as naturalist, I was much struck with certain facts in the distribution of the inhabitants of South America, and in the geological relations of the present to the past inhabitants of that continent. These facts seemed to me to throw some light on the ** origin of species ** that mystery of mysteries, as it has been called by one of our greatest philosophers. 6 | 7 | ## Chapters 8 | 9 | + Variation under domestication. 10 | + Variation under nature. 11 | + Struggle for existence. 12 | + Natural selection. 13 | + ... 14 | 15 | -------------------------------------------------------------------------------- /markdown/markdown2.md: -------------------------------------------------------------------------------- 1 | # Title: markdown is fantastic! 2 | 3 | ## Subtitle: and easy to learn 4 | 5 | For ** bold text ** just use two stars, and for * italic * one star is enough. 6 | 7 | ## A list 8 | 9 | + Apple 10 | + Banana 11 | + Cherry 12 | 13 | -------------------------------------------------------------------------------- /markdown/screen-coupures-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-coupures-1.png -------------------------------------------------------------------------------- /markdown/screen-coupures-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-coupures-2.png -------------------------------------------------------------------------------- /markdown/screen-coupures-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-coupures-3.png -------------------------------------------------------------------------------- /markdown/screen-coupures-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-coupures-4.png -------------------------------------------------------------------------------- /markdown/screen-hyphen-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-hyphen-1.png -------------------------------------------------------------------------------- /markdown/screen-hyphen-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-hyphen-2.png -------------------------------------------------------------------------------- /markdown/screen-hyphen-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-hyphen-3.png -------------------------------------------------------------------------------- /markdown/screen-hyphen-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-hyphen-4.png -------------------------------------------------------------------------------- /markdown/screen-markdown-1-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-1-en.png -------------------------------------------------------------------------------- /markdown/screen-markdown-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-1.png -------------------------------------------------------------------------------- /markdown/screen-markdown-2-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-2-en.png -------------------------------------------------------------------------------- /markdown/screen-markdown-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-2.png -------------------------------------------------------------------------------- /markdown/screen-markdown-3-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-3-en.png -------------------------------------------------------------------------------- /markdown/screen-markdown-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-3.png -------------------------------------------------------------------------------- /markdown/screen-markdown-4-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-4-en.png -------------------------------------------------------------------------------- /markdown/screen-markdown-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-4.png -------------------------------------------------------------------------------- /markdown/screen-markdown-5-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-5-en.png -------------------------------------------------------------------------------- /markdown/screen-markdown-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-5.png -------------------------------------------------------------------------------- /markdown/screen-markdown-6-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-6-en.png -------------------------------------------------------------------------------- /markdown/screen-markdown-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-6.png -------------------------------------------------------------------------------- /markdown/screen-markdown-7-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-7-en.png -------------------------------------------------------------------------------- /markdown/screen-markdown-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-7.png -------------------------------------------------------------------------------- /markdown/screen-markdown-8-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-8-en.png -------------------------------------------------------------------------------- /markdown/screen-markdown-8-en.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[height=5cm]{screen-markdown-8-en.png}}; 4 | \begin{scope}[x={(image.south east)},y={(image.north west)}] 5 | 6 | \draw[->,>=latex,ultra thick,blue] (0,0.9)--++(1,0) node[above]{$x$}; 7 | \draw[->,>=latex,ultra thick,blue] (0,0.9)--++(0,-0.9) node[left]{$y$}; 8 | \coordinate (A) at (0.15,0.75); 9 | \coordinate (B) at (0.35,0.2); 10 | 11 | \draw (A) rectangle (B); 12 | 13 | \coordinate (SW) at (0.49,0.65); 14 | 15 | \fill[black] (A) circle (4pt) node[below left] {$(x_1,y_1)$}; 16 | \fill[black] (B) circle (4pt) node[below right] {$(x_2,y_2)$}; 17 | \fill[red] (SW) circle (4pt) ; 18 | \draw[<-,>=latex,ultra thick,red] (SW) to[bend right=10] (0.7,0.4) node[right]{South West anchor}; 19 | 20 | \fill[blue] (0,0.9) circle (4pt) node[above left] {$(0,0)$}; 21 | 22 | 23 | \end{scope} 24 | 25 | \end{tikzpicture} 26 | -------------------------------------------------------------------------------- /markdown/screen-markdown-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/screen-markdown-8.png -------------------------------------------------------------------------------- /markdown/screen-markdown-8.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[height=5cm]{screen-markdown-8.png}}; 4 | \begin{scope}[x={(image.south east)},y={(image.north west)}] 5 | 6 | \draw[->,>=latex,ultra thick,blue] (0,0.9)--++(0.9,0) node[above]{$x$}; 7 | \draw[->,>=latex,ultra thick,blue] (0,0.9)--++(0,-0.9) node[left]{$y$}; 8 | \coordinate (A) at (0.135,0.855); 9 | \coordinate (B) at (0.34,0.283); 10 | \coordinate (NW) at (0.41,0.707); 11 | 12 | \fill[black] (A) circle (4pt) node[below left] {$(x_1,y_1)$}; 13 | \fill[black] (B) circle (4pt) node[below right] {$(x_2,y_2)$}; 14 | \fill[red] (NW) circle (4pt) ; 15 | \draw[<-,>=latex,ultra thick,red] (NW) to[bend left=10] (0.8,0.8) node[right]{ancre Nord-Ouest}; 16 | 17 | \fill[blue] (0,0.9) circle (4pt) node[above left] {$(0,0)$}; 18 | 19 | 20 | \end{scope} 21 | 22 | \end{tikzpicture} 23 | -------------------------------------------------------------------------------- /markdown/text_markdown.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/markdown/text_markdown.pdf -------------------------------------------------------------------------------- /misc/4eme_couverture.txt: -------------------------------------------------------------------------------- 1 | 2 | # Quatrième de couverture 3 | 4 | * Python au lycée 5 | * Python langage puissant, 6 | * Python facile à débuter 7 | * Guider pas à pas 8 | * Orienté mathématiques 9 | * Niveau math <= seconde 10 | * Activités originales 11 | * Algorithme et programmation 12 | 13 | 14 | Python est le langage idéal pour apprendre la programmation. 15 | C'est un langage puissant qui vous permettra de plonger dans le monde des algorithmes. 16 | 17 | Ce livre vous guide pas à pas à travers des activités mathématiques et informatiques originales adaptées au lycée. Il se complète par des ressources en ligne : tous les codes Python, des vidéos et des fiches en couleurs. 18 | Vous avez tout en main pour réussir ! 19 | 20 | 21 | Premiers pas 22 | Tortue (Scratch avec Python) 23 | Si ... alors ... 24 | Fonctions 25 | Arithmétique -- Boucle tant que -- I 26 | Chaînes de caractères -- Analyse d’un texte 27 | Listes I 28 | Statistique -- Visualisation de données 29 | Fichiers 30 | Arithmétique -- Boucle tant que -- II 31 | Binaire I 32 | Listes II 33 | Binaire II 34 | Probabilités -- Paradoxe de Parrondo 35 | Chercher et remplacer 36 | Calculatrice polonaise -- Piles 37 | Visualiseur de texte -- Markdown 38 | L-système 39 | Images dynamiques 40 | Jeu de la vie 41 | Graphes et combinatoire de Ramsey 42 | Bitcoin 43 | Constructions aléatoires 44 | 45 | -------------------------------------------------------------------------------- /misc/fig-part-lsystem.tikz: -------------------------------------------------------------------------------- 1 | %% Pour figure titre \part python1 2 | %\usetikzlibrary{lindenmayersystems} 3 | % Author: Stefan Kottwitz 4 | %\usetikzlibrary[shadings] 5 | %\pgfdeclarelindenmayersystem{Hilbert curve}{ 6 | % \rule{L -> +RF-LFL-FR+} 7 | % \rule{R -> -LF+RFR+FL-}} 8 | %% Fin figure \part python1 9 | \begin{tikzpicture} 10 | \shadedraw [bottom color=red!80, top color=red!10, draw=red!80!black] 11 | [l-system={Hilbert curve, axiom=L, order=5, step=8pt, angle=90}] 12 | lindenmayer system; 13 | \end{tikzpicture} -------------------------------------------------------------------------------- /misc/logo_exo7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/misc/logo_exo7.png -------------------------------------------------------------------------------- /misc/postface_book_python.tex: -------------------------------------------------------------------------------- 1 | 2 | \clearemptydoublepage 3 | \pagestyle{empty}\thispagestyle{empty} 4 | 5 | \vspace*{\fill} 6 | 7 | \section*{Thanks} 8 | 9 | 10 | I would like to thank Stéphanie Bodin for her encouragement and for testing the activities of the first parts. 11 | I would like to thank Michel Bodin for having tested all the first activities and his proofreading. 12 | Thanks to François Recher for his enthusiasm and careful review of the book. 13 | Thanks to Éric Wegrzynowski for his review and ideas for the activities on the images. 14 | Thanks to Philippe Marquet for his review of the first chapters. Thanks to Kroum Tzanev for the model of the book. 15 | Thanks to Emily Gubski for the English corrections. 16 | 17 | \bigskip 18 | 19 | \begin{center} 20 | You can retrieve all the activity codes \Python{} and all the source files on the Exo7 \emph{GitHub} page: 21 | \href{https://github.com/exo7math/python1-en-exo7}{\og{}GitHub: Python in high school\fg{}}. 22 | 23 | \medskip 24 | 25 | 26 | 27 | 28 | %\\ \centerline{ 29 | %\href{https://www.youtube.com/c/PythonAuLycee}{youtube.com/PythonAuLyce}} 30 | \end{center} 31 | 32 | 33 | \vspace*{\fill} 34 | 35 | \bigskip 36 | 37 | \begin{center} 38 | \LogoExoSept{3} 39 | \end{center} 40 | 41 | 42 | 43 | \begin{center} 44 | This book is distributed under license \emph{Creative Commons -- BY-NC-SA -- 4.0}. 45 | 46 | On the Exo7 website you can download the book in color for free. 47 | \end{center} 48 | 49 | 50 | 51 | 52 | \pagenumbering{gobble} % remove page numbering 53 | \printindex 54 | \pagenumbering{arabic} 55 | 56 | -------------------------------------------------------------------------------- /proba/proba.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/proba/proba.pdf -------------------------------------------------------------------------------- /ramsey/fig-ramsey-0a.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=2] 2 | 3 | \draw[ultra thick,red,dashed] (0,0)--(1,0)--(1,1)--(0,1)--cycle; 4 | \draw[ultra thick,green!60!black] (1,1)--(0,0); 5 | \draw[ultra thick,green!60!black] (0,1)--(1,0); 6 | 7 | \fill[black] (0,0) circle (2pt) node[below left]{2}; 8 | \fill[black] (0,1) circle (2pt) node[above left]{3}; 9 | \fill[black] (1,0) circle (2pt) node[below right]{1}; 10 | \fill[black] (1,1) circle (2pt) node[above right]{0}; 11 | 12 | \end{tikzpicture} -------------------------------------------------------------------------------- /ramsey/fig-ramsey-0b.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=2] 2 | 3 | 4 | \coordinate (A) at (0:2); 5 | \coordinate (B) at (120:2.5); 6 | \coordinate (C) at (-120:1.3); 7 | 8 | \draw[ultra thick,green!60!black] (A)--(B)--(C)--cycle; 9 | 10 | \fill[black] (A) circle (2pt) node[below right]{$i$}; 11 | \fill[black] (B) circle (2pt) node[above left]{$j$}; 12 | \fill[black] (C) circle (2pt) node[below right]{$k$}; 13 | 14 | 15 | \node at (1.2,-1.5) {\bf Three friends}; 16 | 17 | \begin{scope}[xshift=7cm,rotate =30] 18 | \coordinate (A) at (0:2.5); 19 | \coordinate (B) at (120:2); 20 | \coordinate (C) at (-120:1); 21 | \draw[ultra thick,red,dashed] (A)--(B)--(C)--cycle; 22 | 23 | \fill[black] (A) circle (2pt) node[above right]{$i'$}; 24 | \fill[black] (B) circle (2pt) node[above left]{$j'$}; 25 | \fill[black] (C) circle (2pt) node[below left]{$k'$}; 26 | 27 | 28 | \node at (1.6,-1.5) {\bf Three stangers}; 29 | \end{scope} 30 | 31 | 32 | \end{tikzpicture} -------------------------------------------------------------------------------- /ramsey/fig-ramsey-0c.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=2] 2 | 3 | 4 | \coordinate (A) at (0:2); 5 | \coordinate (B) at (70:2); 6 | \coordinate (C) at (144:2); 7 | \coordinate (D) at (-144:2); 8 | \coordinate (E) at (-72:2); 9 | 10 | \draw[ultra thick,green!60!black] (C)--(A)--(E)--(D)--(C)--(B)--(E); 11 | 12 | \draw[line width=2.5pt,red,dashed] (A)--(B)--(D)--cycle; 13 | \draw[ultra thick,red,dashed] (C)--(E); 14 | 15 | \fill[black] (A) circle (3pt) node[below right]{$0$}; 16 | \fill[black] (B) circle (3pt) node[above left]{$4$}; 17 | \fill[black] (C) circle (2pt) node[above left]{$3$}; 18 | \fill[black] (D) circle (3pt) node[below left]{$2$}; 19 | \fill[black] (E) circle (2pt) node[below right]{$1$}; 20 | 21 | \node at (0,-2.5) {\bf A graph with $n=5$ that satifies Ramsey's statement}; 22 | 23 | 24 | 25 | \end{tikzpicture} -------------------------------------------------------------------------------- /ramsey/fig-ramsey-1a.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \begin{scope}[scale=3.5] 4 | \draw[ultra thick,red,dashed] (0,0)--(1,0)--(1,1)--(0,1)--cycle; 5 | \draw[ultra thick,green!60!black] (1,1)--(0,0); 6 | \draw[ultra thick,green!60!black] (0,1)--(1,0); 7 | 8 | \fill[black] (0,0) circle (1pt) node[below left]{2}; 9 | \fill[black] (0,1) circle (1pt) node[above left]{3}; 10 | \fill[black] (1,0) circle (1pt) node[below right]{1}; 11 | \fill[black] (1,1) circle (1pt) node[above right]{0}; 12 | \end{scope} 13 | 14 | % Ramsey - Tableau 15 | \begin{scope}[xshift=10cm,yshift=-0.5cm] 16 | \draw (0,0) grid ++(4,4); 17 | 18 | \node[red] at (0.5,0.5) {\bf 0}; 19 | \node[green!60!black] at (1.5,0.5) {\bf 1}; 20 | \node[red] at (2.5,0.5) {\bf 0}; 21 | \node[red] at (3.5,0.5) {\bf 0}; 22 | 23 | \node[green!60!black] at (0.5,1.5) {\bf 1}; 24 | \node[red] at (1.5,1.5) {\bf 0}; 25 | \node[red] at (2.5,1.5) {\bf 0}; 26 | \node[red] at (3.5,1.5) {\bf 0}; 27 | 28 | \node[red] at (0.5,2.5) {\bf 0}; 29 | \node[red] at (1.5,2.5) {\bf 0}; 30 | \node[red] at (2.5,2.5) {\bf 0}; 31 | \node[green!60!black] at (3.5,2.5) {\bf 1}; 32 | 33 | \node[red] at (0.5,3.5) {\bf 0}; 34 | \node[red] at (1.5,3.5) {\bf 0}; 35 | \node[green!60!black] at (2.5,3.5) {\bf 1}; 36 | \node[red] at (3.5,3.5) {\bf 0}; 37 | 38 | 39 | %\node at (3,-1.5) {\bf Tableau}; 40 | 41 | \draw[->,>=latex,very thick] (0,5) to node[midway, above] {index $j$} ++(4,0) ; 42 | \draw[->,>=latex,very thick] (-1.5,4) to node[midway, left] {index $i$} ++(0,-4) ; 43 | 44 | \node[scale=0.7,above] at (0.5,4) {$j=0$}; 45 | \node[scale=0.7,above] at (1.5,4) {$j=1$}; 46 | \node[scale=0.7,above] at (2.5,4) {$j=2$}; 47 | \node[scale=0.7,above] at (3.5,4) {$j=3$}; 48 | 49 | \node[scale=0.7,left] at (0,3.5) {$i=0$}; 50 | \node[scale=0.7,left] at (0,2.5) {$i=1$}; 51 | \node[scale=0.7,left] at (0,1.5) {$i=2$}; 52 | \node[scale=0.7,left] at (0,0.5) {$i=3$}; 53 | 54 | 55 | \draw[<->,>=latex,very thick,gray] (0,-0.5) to node[midway, below] {$n$} ++(4,0) ; 56 | \draw[<->,>=latex,very thick,gray] (4.5,0) to node[midway, right] {$n$} ++(0,4) ; 57 | 58 | \end{scope} 59 | 60 | \end{tikzpicture} -------------------------------------------------------------------------------- /ramsey/fig-ramsey-2.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \draw[->,>=latex,ultra thick,gray] (-5,0)--(5,0) node[below]{$x$}; 4 | \draw[->,>=latex,ultra thick,gray] (0,-5)--(0,5) node[left]{$y$}; 5 | 6 | \def\r{4}; 7 | \def\n{7}; 8 | 9 | 10 | \draw[gray,ultra thick] (0,0) circle(\r cm); 11 | 12 | 13 | \foreach \i in {0,...,\n}{ 14 | \fill[red] (\i*360/\n:\r) circle(4pt); 15 | 16 | } 17 | 18 | 19 | \foreach \i in {0,1}{ 20 | \node[black,above right] at (\i*360/\n:\r){$(x_\i,y_\i)$} ; 21 | } 22 | 23 | 24 | \node[black,below right] at (-360/\n:\r){$(x_{n-1},y_{n-1})$} ; 25 | 26 | \coordinate (S) at (3*360/\n:\r); 27 | \node[black,above left] at (S) {$(x_{i},y_{i})$} ; 28 | \draw[dashed,very thick, blue] (S) -- (S |- 0,0) node[below] {$x_i = r\cos(\frac{2 i\pi}{n})$}; 29 | \draw[dashed,very thick, blue] (S) -- (S -| 0,0) node[right] {$y_i = r\sin(\frac{2 i\pi}{n})$}; 30 | 31 | 32 | \node[black,below right] at (0,0) {$(0,0)$} ; 33 | \draw[gray,very thick, below right] (0,0)--(-140:\r) node[midway, below right,black] {$r$} ; 34 | \end{tikzpicture} -------------------------------------------------------------------------------- /ramsey/fig-ramsey-4a.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | 5 | \draw (0,0) grid ++(6,1); 6 | 7 | \node at(-5,0.5) {$p = 26$}; 8 | \node at(-5,0) {$(n = 6)$}; 9 | 10 | \node at(-5,-1.5) {\bf Initial integer $p$}; 11 | 12 | \draw[->,>=latex,ultra thick, blue] (-3.5,0.5)--++(2,0); 13 | 14 | \node at (0.5,0.5) {\bf 0}; 15 | \node[red] at (1.5,0.5) {\bf 1}; 16 | \node[red] at (2.5,0.5) {\bf 1}; 17 | \node at (3.5,0.5) {\bf 0}; 18 | \node[red] at (4.5,0.5) {\bf 1}; 19 | \node at (5.5,0.5) {\bf 0}; 20 | 21 | \node at (-0.5,-0.47) {rank : }; 22 | \node at (0.5,-0.5) {0}; 23 | \node[blue] at (1.5,-0.5) {1}; 24 | \node[blue] at (2.5,-0.5) {2}; 25 | \node at (3.5,-0.5) {3}; 26 | \node[blue] at (4.5,-0.5) {4}; 27 | \node at (5.5,-0.5) {5}; 28 | 29 | \node at(3,-1.5) {\bf Binary notation of $p$ using $n$ bits}; 30 | 31 | 32 | \draw[->,>=latex,ultra thick, blue] (7,0.5)--++(2,0); 33 | 34 | \node[scale=1.4,blue] at (11,0.5) {$\{1,2,4\}$}; 35 | 36 | \node at(11,-1.5) {\bf Subset associated to $p$}; 37 | 38 | 39 | \end{tikzpicture} -------------------------------------------------------------------------------- /ramsey/fig-ramsey-4b.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | 5 | \draw (0,0) grid ++(8,1); 6 | 7 | \node at(-5,0.5) {$p = 57$}; 8 | \node at(-5,0) {$(n = 8)$}; 9 | 10 | \node at(-5,-1.5) {\bf Initial integer $p$}; 11 | 12 | \draw[->,>=latex,ultra thick, blue] (-3.5,0.5)--++(2,0); 13 | 14 | \node at (0.5,0.5) {\bf 0}; 15 | \node at (1.5,0.5) {\bf 0}; 16 | \node[red] at (2.5,0.5) {\bf 1}; 17 | \node[red] at (3.5,0.5) {\bf 1}; 18 | \node[red] at (4.5,0.5) {\bf 1}; 19 | \node at (5.5,0.5) {\bf 0}; 20 | \node at (6.5,0.5) {\bf 0}; 21 | \node[red] at (7.5,0.5) {\bf 1}; 22 | 23 | 24 | \node at (-0.5,-0.47) {rank : }; 25 | \node at (0.5,-0.5) {0}; 26 | \node at (1.5,-0.5) {1}; 27 | \node[blue] at (2.5,-0.5) {2}; 28 | \node[blue] at (3.5,-0.5) {3}; 29 | \node[blue] at (4.5,-0.5) {4}; 30 | \node at (5.5,-0.5) {5}; 31 | \node at (6.5,-0.5) {6}; 32 | \node[blue] at (7.5,-0.5) {7}; 33 | 34 | \node at(4,-1.5) {\bf Binary notation of $p$ using $n$ bits}; 35 | 36 | 37 | \draw[->,>=latex,ultra thick, blue] (9,0.5)--++(2,0); 38 | 39 | \node[scale=1.4,blue] at (13,0.5) {$\{2,3,4,7\}$}; 40 | 41 | \node at(13,-1.5) {\bf Subset associated to $p$}; 42 | 43 | 44 | \end{tikzpicture} -------------------------------------------------------------------------------- /ramsey/fig-ramsey-6.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=2] 2 | 3 | \draw[ultra thick,green!60!black] (0,0)--(1,0)--(1,1)--(0,1)--(0,0)--(1,1); 4 | \draw[ultra thick,green!60!black] (0,1)--(1,0); 5 | 6 | \fill[black] (0,0) circle (2pt); 7 | \fill[black] (0,1) circle (2pt); 8 | \fill[black] (1,0) circle (2pt); 9 | \fill[black] (1,1) circle (2pt); 10 | 11 | 12 | 13 | \end{tikzpicture} -------------------------------------------------------------------------------- /ramsey/ramsey.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ramsey/ramsey.pdf -------------------------------------------------------------------------------- /ramsey/ramsey_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Ramsey graphs and combinatorics 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 3 - Binary 9 | ############################## 10 | 11 | 12 | def integer_to_binary(p,n): 13 | str_b = bin(p) # Conversion to binary notation 14 | str_bb = str_b[2:] # We cut off the prefix 15 | # Transformation to a list of **intgers** 0 or 1 16 | list_binary = [] 17 | for b in str_bb: 18 | list_binary = list_binary + [int(b)] 19 | 20 | # Add zeros at the begining if necessary 21 | nb_zeros = n - len(list_binary) 22 | for i in range(nb_zeros): 23 | list_binary = [0] + list_binary 24 | 25 | return list_binary 26 | 27 | 28 | # Short version, using "format()" 29 | def integer_to_binary_bis(p,n): 30 | model = '{:0'+str(n)+'b}' 31 | str_binary = model.format(p) 32 | list_binary = [int(b) for b in list(str_binary)] 33 | return list_binary 34 | 35 | 36 | # Test 37 | if __name__ == '__main__': 38 | n = 8 39 | p = 37 40 | print(integer_to_binary(p,n)) 41 | print(integer_to_binary_bis(p,n)) 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ramsey/ramsey_4.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Ramsey graphs and combinatorics 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 4 - Subsets 9 | ############################## 10 | 11 | from ramsey_3 import integer_to_binary 12 | 13 | 14 | ############################## 15 | ############################## 16 | 17 | 18 | 19 | ## Question 1 ## 20 | 21 | 22 | # Genration of all subsets 23 | 24 | ################################################## 25 | def subsets(n): 26 | """Find all subsets of a set [0,1,2,...n-1] having n elements """ 27 | 28 | all_subsets = [] 29 | 30 | for p in range(2**n): 31 | 32 | # Binary conversion 33 | list_binary = integer_to_binary(p,n) 34 | #print(list_binary) 35 | 36 | sub = [] 37 | for j in range(n): 38 | # if list_binary[n-j-1] == 1: 39 | if list_binary[j] == 1: 40 | sub = sub + [j] 41 | 42 | all_subsets = all_subsets + [sub] 43 | 44 | return all_subsets 45 | 46 | # Test 47 | if __name__ == '__main__': 48 | print("--- Subsets ---") 49 | n = 3 50 | SS_ENS = subsets(n) 51 | print("For n = ",n) 52 | print("Number of subsets = ",len(SS_ENS)) 53 | print(SS_ENS) 54 | 55 | 56 | ## Question 2 ## 57 | 58 | ################################################## 59 | def fix_subsets(n,k): 60 | all_fix_subsets = [] 61 | for sub in subsets(n): 62 | if len(sub) == k: 63 | all_fix_subsets = all_fix_subsets + [sub] 64 | return all_fix_subsets 65 | 66 | # Test (suite) 67 | if __name__ == '__main__': 68 | print("--- Sous-ensembles à 3 éléments ---") 69 | 70 | n = 6 71 | k = 3 72 | SS_ENS_3 = fix_subsets(n,k) 73 | print("For n = ",n," k = ",k) 74 | print("Number of subsets having",k,"elements = ",len(SS_ENS_3)) 75 | print(SS_ENS_3) 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /ramsey/screen-ramsey-1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ramsey/screen-ramsey-1a.png -------------------------------------------------------------------------------- /ramsey/screen-ramsey-1b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ramsey/screen-ramsey-1b.png -------------------------------------------------------------------------------- /ramsey/screen-ramsey-1c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ramsey/screen-ramsey-1c.png -------------------------------------------------------------------------------- /ramsey/screen-ramsey-1d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ramsey/screen-ramsey-1d.png -------------------------------------------------------------------------------- /ramsey/screen-ramsey-2-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ramsey/screen-ramsey-2-en.png -------------------------------------------------------------------------------- /ramsey/screen-ramsey-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/ramsey/screen-ramsey-2.png -------------------------------------------------------------------------------- /stacks/fig-sort1.tikz: -------------------------------------------------------------------------------- 1 | 2 | \begin{tikzpicture}[scale=0.8] 3 | 4 | 5 | 6 | \draw[ultra thick,blue,fill = blue!10] (0,0) rectangle ++(3,1); 7 | \node at (1.5,0.5) {\bf 7}; 8 | 9 | \draw[ultra thick,red,fill = red!10] (4,0) rectangle ++(3,1); 10 | \node at (5.5,0.5) {\bf W}; 11 | 12 | \draw[ultra thick,blue,fill = blue!10] (8,0) rectangle ++(3,1); 13 | \node at (9.5,0.5) {\bf 13}; 14 | 15 | \draw[ultra thick,red,fill = red!10] (12,0) rectangle ++(3,1); 16 | \node at (13.5,0.5) {\bf G}; 17 | 18 | \draw[ultra thick,red,fill = red!10] (16,0) rectangle ++(3,1); 19 | \node at (17.5,0.5) {\bf S}; 20 | 21 | \draw[ultra thick,blue,fill = blue!10] (20,0) rectangle ++(3,1); 22 | \node at (21.5,0.5) {\bf 5}; 23 | 24 | \foreach \x in {3,7,...,19}{ 25 | \draw[ultra thick] (\x,0.5)--++(1,0); 26 | } 27 | 28 | \draw[ultra thick,->,>=latex] (0,0.5)--++(-1,0); 29 | 30 | \node at (11.5,-1) {\bf Unsorted train.}; 31 | 32 | \end{tikzpicture} 33 | -------------------------------------------------------------------------------- /stacks/fig-sort2.tikz: -------------------------------------------------------------------------------- 1 | 2 | \begin{tikzpicture}[scale=0.8] 3 | 4 | \draw[ultra thick,blue,fill = blue!10] (0,0) rectangle ++(3,1); 5 | \node at (1.5,0.5) {\bf 7}; 6 | 7 | \draw[ultra thick,blue,fill = blue!10] (4,0) rectangle ++(3,1); 8 | \node at (5.5,0.5) {\bf 5}; 9 | 10 | \draw[ultra thick,blue,fill = blue!10] (8,0) rectangle ++(3,1); 11 | \node at (9.5,0.5) {\bf 13}; 12 | 13 | \draw[ultra thick,red,fill = red!10] (12,0) rectangle ++(3,1); 14 | \node at (13.5,0.5) {\bf W}; 15 | 16 | \draw[ultra thick,red,fill = red!10] (16,0) rectangle ++(3,1); 17 | \node at (17.5,0.5) {\bf S}; 18 | 19 | \draw[ultra thick,red,fill = red!10] (20,0) rectangle ++(3,1); 20 | \node at (21.5,0.5) {\bf G}; 21 | 22 | 23 | \foreach \x in {3,7,...,19}{ 24 | \draw[ultra thick] (\x,0.5)--++(1,0); 25 | } 26 | 27 | \draw[ultra thick,->,>=latex] (0,0.5)--++(-1,0); 28 | 29 | \node at (11.5,-1) {\bf Sorted train.}; 30 | 31 | \end{tikzpicture} 32 | -------------------------------------------------------------------------------- /stacks/fig-stacks1.tikz: -------------------------------------------------------------------------------- 1 | 2 | \usetikzlibrary{patterns} 3 | 4 | \begin{tikzpicture}[scale=0.8] 5 | 6 | \draw[ultra thick] (-3,0) -- (3,0); 7 | \fill[pattern=north west lines] (-3,-1) rectangle (3,0); 8 | 9 | 10 | \draw[thick] (-2,0) rectangle ++(4,1); 11 | \node at (0,0.5) {$7$}; 12 | 13 | \draw[thick] (-2,1) rectangle ++(4,1); 14 | \node at (0,1.5) {$3$}; 15 | 16 | \draw[thick] (-2,2) rectangle ++(4,1); 17 | \node at (0,2.5) {$11$}; 18 | 19 | \draw[thick] (-2,3) rectangle ++(4,1); 20 | \node at (0,3.5) {$6$}; 21 | 22 | \node at (0,-2) {\bf A stack of integers}; 23 | 24 | 25 | %% Sommets 26 | 27 | \node[right] at (14.1,6) {Top of the stack}; 28 | \draw[->,>=latex,thick ] (14,6) to[bend right] (10,6.5); 29 | 30 | 31 | \begin{scope}[xshift=8cm] 32 | \draw[ultra thick] (-3,0) -- (3,0); 33 | \fill[pattern=north west lines] (-3,-1) rectangle (3,0); 34 | 35 | 36 | \draw[thick] (-2,0) rectangle ++(4,1); 37 | \node at (0,0.5) {"When"}; 38 | 39 | \draw[thick] (-2,1) rectangle ++(4,1); 40 | \node at (0,1.5) {"As"}; 41 | 42 | \draw[thick] (-2,2) rectangle ++(4,1); 43 | \node at (0,2.5) {"Still"}; 44 | 45 | \draw[thick] (-2,3) rectangle ++(4,1); 46 | \node at (0,3.5) {"While"}; 47 | 48 | \draw[thick] (-2,4) rectangle ++(4,1); 49 | \node at (0,4.5) {"If"}; 50 | 51 | \draw[thick] (-2,5) rectangle ++(4,1); 52 | \node at (0,5.5) {"Unless"}; 53 | 54 | \draw[thick] (-2,6) rectangle ++(4,1); 55 | \node at (0,6.5) {"Because"}; 56 | 57 | \node at (0,-2) {\bf A stack of strings}; 58 | \end{scope} 59 | 60 | \begin{scope}[xshift=16cm] 61 | 62 | \draw[ultra thick] (-3,0) -- (3,0); 63 | \fill[pattern=north west lines] (-3,-1) rectangle (3,0); 64 | 65 | \node at (0,-2) {\bf An empty stack}; 66 | \end{scope} 67 | 68 | \end{tikzpicture} 69 | -------------------------------------------------------------------------------- /stacks/fig-stacks3.tikz: -------------------------------------------------------------------------------- 1 | 2 | \usetikzlibrary{patterns} 3 | 4 | \begin{tikzpicture}[scale=0.8] 5 | 6 | \draw[ultra thick] (-3,0) -- (3,0); 7 | \fill[pattern=north west lines] (-3,-1) rectangle (3,0); 8 | 9 | \draw[thick] (-2,0) rectangle ++(4,1); 10 | \node at (0,0.5) {$4$}; 11 | 12 | \draw[thick] (-2,1) rectangle ++(4,1); 13 | \node at (0,1.5) {$2$}; 14 | 15 | \draw[thick] (-2,2) rectangle ++(4,1); 16 | \node at (0,2.5) {$11$}; 17 | 18 | \draw[thick] (-2,3) rectangle ++(4,1); 19 | \node at (0,3.5) {$7$}; 20 | 21 | \node at (0,-2) {\bf A stack}; 22 | 23 | 24 | \begin{scope}[xshift=10cm] 25 | 26 | \node[scale=1.1] at (0,1) {\bf\texttt{stack = [4,2,11,7]}}; 27 | \node at (0,-2) {\bf Model as a list}; 28 | 29 | \end{scope} 30 | 31 | \end{tikzpicture} 32 | -------------------------------------------------------------------------------- /stacks/polish1.tikz: -------------------------------------------------------------------------------- 1 | 2 | \tikzstyle{line} = [draw, thick] 3 | 4 | \begin{tikzpicture} 5 | 6 | \node at (0,0) {$2+3$}; 7 | \node at (0,-2) {Notation alg\'ebrique classique}; 8 | 9 | 10 | \begin{scope}[xshift=5cm,yshift=1cm] 11 | \path node(P1) {$2$ }; 12 | \path (P1)+(2,0) node(P2) {$3$}; 13 | \path (P1)+(1,-1.5) node(P3){$+$}; 14 | 15 | % Draw arrows between elements 16 | \path[line] (P1.south) -- node [above] {} (P3); 17 | \path[line] (P2.south) -- node [above] {} (P3); 18 | 19 | \node at (1,-3) {Notation par un arbre}; 20 | \end{scope} 21 | 22 | \begin{scope}[xshift=12cm] 23 | 24 | \node at (0,0) {$2 \ \ 3 \ \ +$}; 25 | \node at (0,-2) {\'Ecriture polonaise}; 26 | \end{scope} 27 | 28 | \end{tikzpicture} 29 | -------------------------------------------------------------------------------- /stacks/polish2.tikz: -------------------------------------------------------------------------------- 1 | 2 | \tikzstyle{line} = [draw, thick] 3 | 4 | \begin{tikzpicture} 5 | 6 | \node at (0,0) {$(10+5) \times 3$}; 7 | 8 | 9 | 10 | \begin{scope}[xshift=5cm,yshift=2cm] 11 | \path node(P1) {$10$ }; 12 | \path (P1)+(2,0) node(P2) {$5$}; 13 | \path (P1)+(1,-1.5) node(P3){$+$}; 14 | \path (P3)+(2,0) node(P4) {$3$}; 15 | \path (P3)+(1,-1.5) node(P5){$\times$}; 16 | 17 | % Draw arrows between elements 18 | \path[line] (P1.south) -- node [above] {} (P3); 19 | \path[line] (P2.south) -- node [above] {} (P3); 20 | \path[line] (P3.south) -- node [above] {} (P5); 21 | \path[line] (P4.south) -- node [above] {} (P5); 22 | \end{scope} 23 | 24 | \begin{scope}[xshift=12cm] 25 | \node at (0,0) {$10 \ \ 5 \ + \ 3 \ \ \times$}; 26 | \end{scope} 27 | 28 | \end{tikzpicture} 29 | -------------------------------------------------------------------------------- /stacks/stacks.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/stacks/stacks.pdf -------------------------------------------------------------------------------- /stacks/stacks_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Stacks - Polish calculator 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 1 - Operations on the stack 9 | ############################## 10 | 11 | 12 | # "stack" is a global variable 13 | 14 | ## Question 1 ## 15 | 16 | def push_to_stack(element): 17 | """ Add an element at the top of the stack 18 | Input: an object 19 | Output: nothing 20 | Action: the stack contains one more element """ 21 | 22 | global stack # In order to modify the stack 23 | 24 | stack = stack + [element] 25 | 26 | return None 27 | 28 | 29 | # Test 30 | print("--- Push ---") 31 | stack = [4,5,6] 32 | print('Stack before:',stack) 33 | push_to_stack(7) 34 | print('Stack after:',stack) 35 | 36 | 37 | ## Question 2 ## 38 | 39 | def pop_from_stack(): 40 | """ Read the element at the top of stack et remove it 41 | Input: nothing 42 | Output: the element at the top 43 | Action: the stack contains one element less """ 44 | 45 | global stack 46 | 47 | top = stack[len(stack)-1] 48 | stack = stack[0:len(stack)-1] 49 | 50 | return top 51 | 52 | 53 | # Test 54 | print("--- Pop ---") 55 | stack = [4,5,6] 56 | print('Stack before:',stack) 57 | val = pop_from_stack() 58 | print('Popped value:',val,'\nStack after:',stack) 59 | 60 | 61 | ## Question 3 ## 62 | 63 | def is_stack_empty(): 64 | """ Test if the stack is empty or not 65 | Input: nothing 66 | Output: true/false 67 | Action: doesn't modify the stack """ 68 | 69 | if len(stack) == 0: 70 | return True 71 | else: 72 | return False 73 | 74 | 75 | # Tests 76 | print("--- Test if stack empty ---") 77 | 78 | # Test 1 79 | stack = [4,5,6] 80 | empty = is_stack_empty() 81 | print(stack,'stack empty?',empty) 82 | 83 | # Test 2 84 | stack = [] 85 | empty = is_stack_empty() 86 | print(stack,'stack empty?',empty) 87 | 88 | -------------------------------------------------------------------------------- /stacks/stacks_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Stacks - Polish calculator 4 | ############################## 5 | 6 | 7 | ############################## 8 | # From activity 1 9 | ############################## 10 | 11 | def push_to_stack(element): 12 | global stack 13 | stack = stack + [element] 14 | return None 15 | 16 | def pop_from_stack(): 17 | global stack 18 | top = stack[len(stack)-1] 19 | stack = stack[0:len(stack)-1] 20 | return top 21 | 22 | def is_stack_empty(): 23 | if len(stack) == 0: 24 | return True 25 | else: 26 | return False 27 | 28 | ############################## 29 | # Activity 3 - La gare de triage 30 | ############################## 31 | 32 | 33 | def sort_wagons(train): 34 | """ Sort red/blue wagons of a train 35 | Input: a train with blue wagons (numbers) and red ones (letters) 36 | Output: the wagons sorted with blue before, then red 37 | Action: use a stack """ 38 | 39 | global stack # Should be global to be modified 40 | stack = [] 41 | 42 | new_train = "" 43 | 44 | for wagon in train.split(): 45 | if wagon.isdigit(): # Blue wagin directly to output station 46 | new_train = new_train + wagon + " " 47 | else: # Red wagon in waiting area 48 | push_to_stack(wagon) 49 | 50 | # Now all blue wagons are well placed 51 | # We deal with the red ones 52 | while not is_stack_empty(): 53 | wagon = pop_from_stack() 54 | new_train = new_train + wagon + " " 55 | 56 | return new_train 57 | 58 | 59 | # Tests 60 | print("--- Red/blue sort ---") 61 | 62 | train = "A 4 C 12" 63 | sorted_train = sort_wagons(train) 64 | print(train,' -> ',sorted_train) 65 | 66 | train = "9 K 8 P 17 L B R 3 10 2 N" 67 | sorted_train = sort_wagons(train) 68 | print(train,' -> ',sorted_train) -------------------------------------------------------------------------------- /stacks/stacks_lesson.py: -------------------------------------------------------------------------------- 1 | mystring = "1776" # A string 2 | if mystring.isdigit(): 3 | myinteger = int(mystring) # myinteger is an integer 4 | else: # Problem 5 | print("I don't know how to convert this string to an integer!") -------------------------------------------------------------------------------- /statistics/fig-stat-arc.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \coordinate (A) at (-2,2); 4 | \coordinate (B) at (2,-2); 5 | \fill (A) circle (3pt) node[left] {$(x_1,y_1)$}; 6 | \fill (B) circle (3pt) node[right] {$(x_2,y_2)$}; 7 | \draw[ultra thick,dashed] (A) rectangle (B); 8 | 9 | \draw[red,very thick,dashed] (0,0) circle (2); 10 | \draw[red,very thick,dashed] (0,0)--(2,0); 11 | 12 | \draw[ultra thick, blue] (0,0) -- (30:2) arc(30:120:2) -- cycle; 13 | 14 | \draw[->,>=latex,ultra thick, red] (0:2.5) arc (0:30:2.5) node[midway,right] {start=$\theta_0$}; 15 | \draw[->,>=latex,ultra thick, blue] (30:2.5) arc (30:120:2.5) node[midway,above] {extent=$\theta$}; 16 | 17 | \fill (0,0) circle (4pt) node[below left] {$O$}; 18 | 19 | \end{tikzpicture} 20 | -------------------------------------------------------------------------------- /statistics/fig-stat-boite.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \draw[blue,line width=3] (0,-1)rectangle ++(6,2); 4 | \draw[fill=blue] (0,-0.2)rectangle ++(-7,0.4); 5 | \draw[fill=blue] (6,-0.2)rectangle ++(4,0.4); 6 | 7 | \draw[fill=blue] (3.5,-1)rectangle ++(0.2,2); 8 | 9 | 10 | \draw[<-,>=latex,ultra thick,red] (-7,0.3) to[bend left=10] ++(1,2) node[above right]{minimum}; 11 | \draw[<-,>=latex,ultra thick,red] (10,0.3) to[bend left=10] ++(1,2) node[above right]{maximum}; 12 | 13 | 14 | \draw[<-,>=latex,ultra thick,red] (3.6,1.1) to[bend left=10] ++(1,2) node[above]{median}; 15 | 16 | \draw[<-,>=latex,ultra thick,red] (0,1.1) to[bend left=10] ++(1,2) node[above right]{$Q_1$}; 17 | \draw[<-,>=latex,ultra thick,red] (6,1.1) to[bend left=10] ++(1,2) node[above right]{$Q_3$}; 18 | 19 | \end{tikzpicture} 20 | -------------------------------------------------------------------------------- /statistics/fig-stat-lesson-intro.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | 4 | \draw[->,>=latex,ultra thick] (0,10)--++(10,0) node[above]{$x$}; 5 | \draw[->,>=latex,ultra thick] (0,10)--++(0,-7) node[left]{$y$}; 6 | 7 | 8 | \coordinate (A) at (4,9); 9 | \coordinate (B) at (9,7); 10 | \fill[blue] (A) circle (4pt) node[above left] {$(x_1,y_1)$}; 11 | \fill[blue] (B) circle (4pt) node[below right] {$(x_2,y_2)$}; 12 | \draw[ultra thick,blue] (A) rectangle (B); 13 | 14 | 15 | 16 | 17 | 18 | \draw[ultra thick,red] (4,5) circle (3 and 1); 19 | \coordinate (AA) at (1,6); 20 | \coordinate (BB) at (7,4); 21 | \fill[red] (AA) circle (4pt) node[above] {$(x_1,y_1)$}; 22 | \fill[red] (BB) circle (4pt) node[below] {$(x_2,y_2)$}; 23 | \draw[thick,dashed,red] (AA) rectangle (BB); 24 | \fill (0,10) circle (4pt) node[above left] {$(0,0)$}; 25 | 26 | 27 | 28 | \end{tikzpicture} 29 | -------------------------------------------------------------------------------- /statistics/lesson_tkinter_buttons.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Statistics -- Data visualization -- tkinter 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Lesson tkinter - Buttons 9 | ############################## 10 | 11 | 12 | from tkinter import * 13 | from random import * 14 | 15 | root = Tk() 16 | canvas = Canvas(root, width=400, height=200, background="white") 17 | canvas.pack(fill="both", expand=True) 18 | 19 | def action_button(): 20 | canvas.delete("all") # Clear all 21 | colors = ["red","orange","yellow","green","cyan","blue","violet","purple"] 22 | col = choice(colors) # Random color 23 | canvas.create_rectangle(100,50,300,150,width=5,fill=col) 24 | return 25 | 26 | button_color = Button(root,text="View", width=20, command=action_button) 27 | button_color.pack(pady=10) 28 | 29 | button_quit = Button(root,text="Quit", width=20, command=root.quit) 30 | button_quit.pack(side=BOTTOM, pady=10) 31 | 32 | root.mainloop() 33 | 34 | -------------------------------------------------------------------------------- /statistics/lesson_tkinter_intro.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Statistics -- Data visualization -- tkinter 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Lesson tkinter 9 | ############################## 10 | 11 | # tkinter module 12 | from tkinter import * 13 | 14 | # tkinter window 15 | root = Tk() 16 | 17 | canvas = Canvas(root, width=800, height=600, background="white") 18 | canvas.pack(fill="both", expand=True) 19 | 20 | 21 | # A rectangle 22 | canvas.create_rectangle(50,50,150,100,width=2) 23 | 24 | # A rectangle with thick blue edges 25 | canvas.create_rectangle(200,50,300,150,width=5,outline="blue") 26 | 27 | # A rectangle filled with purple 28 | canvas.create_rectangle(350,100,500,150,fill="purple") 29 | 30 | # An ellipse 31 | canvas.create_oval(50,110,180,160,width=4) 32 | 33 | # Some text 34 | canvas.create_text(400,75,text="Bla bla bla bla",fill="blue") 35 | 36 | # Launch of the window 37 | root.mainloop() 38 | 39 | -------------------------------------------------------------------------------- /statistics/screen-stat-2a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-2a.png -------------------------------------------------------------------------------- /statistics/screen-stat-2b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-2b.png -------------------------------------------------------------------------------- /statistics/screen-stat-2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-2c.png -------------------------------------------------------------------------------- /statistics/screen-stat-2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-2d.png -------------------------------------------------------------------------------- /statistics/screen-stat-2e-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-2e-en.png -------------------------------------------------------------------------------- /statistics/screen-stat-2e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-2e.png -------------------------------------------------------------------------------- /statistics/screen-stat-4-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-4-en.png -------------------------------------------------------------------------------- /statistics/screen-stat-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-4.png -------------------------------------------------------------------------------- /statistics/screen-stat-5a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-5a.png -------------------------------------------------------------------------------- /statistics/screen-stat-5b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-5b.png -------------------------------------------------------------------------------- /statistics/screen-stat-lesson-buttons-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-lesson-buttons-en.png -------------------------------------------------------------------------------- /statistics/screen-stat-lesson-buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-lesson-buttons.png -------------------------------------------------------------------------------- /statistics/screen-stat-lesson-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/screen-stat-lesson-intro.png -------------------------------------------------------------------------------- /statistics/statistics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/statistics/statistics.pdf -------------------------------------------------------------------------------- /strings/fables.txt: -------------------------------------------------------------------------------- 1 | MAITRE CORBEAU SUR UN ARBRE PERCHE TENAIT EN SON BEC UN FROMAGE MAITRE RENARD PAR L ODEUR ALLECHE LUI TINT A PEU PRES CE LANGAGE ET BONJOUR MONSIEUR DU CORBEAU QUE VOUS ETES JOLI QUE VOUS ME SEMBLEZ BEAU SANS MENTIR SI VOTRE RAMAGE SE RAPPORTE A VOTRE PLUMAGE VOUS ETES LE PHENIX DES HOTES DE CES BOIS A CES MOTS LE CORBEAU NE SE SENT PAS DE JOIE ET POUR MONTRER SA BELLE VOIX IL OUVRE UN LARGE BEC LAISSE TOMBER SA PROIE LE RENARD S EN SAISIT ET DIT MON BON MONSIEUR APPRENEZ QUE TOUT FLATTEUR VIT AUX DEPENS DE CELUI QUI L ECOUTE CETTE LEÇON VAUT BIEN UN FROMAGE SANS DOUTE LE CORBEAU HONTEUX ET CONFUS JURA MAIS UN PEU TARD QU ON NE L Y PRENDRAIT PLUS 2 | 3 | 4 | WER REITET SO SPAT DURCH NACHT UND WIND ES IST DER VATER MIT SEINEM KIND ER HAT DEN KNABEN WOHL IN DEM ARM ER FASST IHN SICHER ER HALT IHN WARM MEIN SOHN WAS BIRGST DU SO BANG DEIN GESICHT SIEHST VATER DU DEN ERLKONIG NICHT DEN ERLENKONIG MIT KRON UND SCHWEIF MEIN SOHN ES IST EIN NEBELSTREIF DU LIEBES KIND KOMM GEH MIT MIR GAR SCHONE SPIELE SPIEL ICH MIT DIR MANCH BUNTE BLUMEN SIND AN DEM STRAND MEINE MUTTER HAT MANCH GULDEN GEWAND MEIN VATER MEIN VATER UND HOREST DU NICHT WAS ERLENKONIG MIR LEISE VERSPRICHT SEI RUHIG BLEIBE RUHIG MEIN KIND IN DURREN BLATTERN SAUSELT DER WIND 5 | 6 | 7 | FASCINADO POR UNA REALIDAD INMEDIATA QUE ENTONCES LE RESULTO MAS FANTASTICA QUE EL VASTO UNIVERSO DE SU IMAGINACION PERDIO TODO INTERES POR EL LABORATORIO DE ALQUIMIA PUSO A DESCANSAR LA MATERIA EXTENUADA POR LARGOS MESES DE MANIPULACION Y VOLVIO A SER EL HOMBRE EMPRENDEDOR DE LOS PRIMEROS TIEMPOS QUE DECIDIA EL TRAZADO DE LAS CALLES Y LA POSICION DE LAS NUEVAS CASAS Y SE DETERMINO QUE FUERA EL QUIEN DIRIGIERA LA REPARTICION DE LA TIERRA 8 | 9 | SUMMERTIME AND THE LIVING IS EASY FISH ARE JUMPING AND THE COTTON IS HIGH OH YOUR DADDY IS RICH AND YOUR MA IS GOOD LOOKING SO HUSH LITTLE BABY DONT YOU CRY ONE OF THESE MORNINGS YOU RE GONNA RISE UP SINGING AND YOULL SPREAD YOUR WINGS AND YOULL TAKE TO THE SKY BUT TILL THAT MORNING THERE AINT NOTHING CAN HARM YOU WITH DADDY AND MAMMY STANDING BY 10 | 11 | 12 | -------------------------------------------------------------------------------- /strings/frequences.txt: -------------------------------------------------------------------------------- 1 | Lettre & Anglais & Français & Allemand & Espagnol \\ 2 | a&8.167\%&8.173\%&7.094\%&12.027\% \\ 3 | b&1.492\%&0.901\%&1.886\%&2.215\% \\ 4 | c&2.782\%&3.345\%&2.732\%&4.019\% \\ 5 | d&4.253\%&3.669\%&5.076\%&5.010\% \\ 6 | e&12.702\%&16.734\%&16.396\%&12.614\% \\ 7 | f&2.228\%&1.066\%&1.656\%&0.692\% \\ 8 | g&2.015\%&0.866\%&3.009\%&1.768\% \\ 9 | h&6.094\%&0.737\%&4.577\%&0.703\% \\ 10 | i&6.966\%&7.579\%&6.550\%&6.972\% \\ 11 | j&0.153\%&0.613\%&0.268\%&0.493\% \\ 12 | k&0.772\%&0.049\%&1.417\%&0.011\% \\ 13 | l&4.025\%&5.456\%&3.437\%&4.967\% \\ 14 | m&2.406\%&2.968\%&2.534\%&3.157\% \\ 15 | n&6.749\%&7.095\%&9.776\%&7.023\% \\ 16 | o&7.507\%&5.819\%&3.037\%&9.510\% \\ 17 | p&1.929\%&2.521\%&0.670\%&2.510\% \\ 18 | q&0.095\%&1.362\%&0.018\%&0.877\% \\ 19 | r&5.987\%&6.693\%&7.003\%&6.871\% \\ 20 | s&6.327\%&7.948\%&7.577\%&7.977\% \\ 21 | t&9.056\%&7.244\%&6.154\%&4.632\% \\ 22 | u&2.758\%&6.429\%&5.161\%&3.107\% \\ 23 | v&0.978\%&1.838\%&0.846\%&1.138\% \\ 24 | w&2.360\%&0.074\%&1.921\%&0.017\% \\ 25 | x&0.150\%&0.427\%&0.034\%&0.215\% \\ 26 | y&1.974\%&0.128\%&0.039\%&1.008\% \\ 27 | z&0.074\%&0.326\%&1.134\%&0.467\% \\ 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /strings/strings-unicode.tikz: -------------------------------------------------------------------------------- 1 | 2 | \begin{tikzpicture} 3 | 4 | \foreach \x in {33,...,42}{ 5 | \node at (0,-\x+33) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 6 | } 7 | \foreach \x in {43,...,52}{ 8 | \node at (2,-\x+43) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 9 | } 10 | \foreach \x in {53,...,62}{ 11 | \node at (4,-\x+53) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 12 | } 13 | \foreach \x in {63,...,72}{ 14 | \node at (6,-\x+63) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 15 | } 16 | \foreach \x in {73,...,82}{ 17 | \node at (8,-\x+73) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 18 | } 19 | \foreach \x in {83,...,92}{ 20 | \node at (10,-\x+83) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 21 | } 22 | \foreach \x in {93,...,102}{ 23 | \node at (12,-\x+93) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 24 | } 25 | \foreach \x in {103,...,112}{ 26 | \node at (14,-\x+103) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 27 | } 28 | \foreach \x in {113,...,122}{ 29 | \node at (16,-\x+113) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 30 | } 31 | \foreach \x in {123,...,127}{ 32 | \node at (18,-\x+123) {{\scriptsize \x} \ \ \bf\symbol{\x}}; 33 | } 34 | \end{tikzpicture} -------------------------------------------------------------------------------- /strings/strings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/strings/strings.pdf -------------------------------------------------------------------------------- /strings/text_languages.txt: -------------------------------------------------------------------------------- 1 | WRE TREITE SO TSPA CUDHR AHNCT UND WIND SE STI RED AEVRT MTI 2 | ESEIMN IDNK RE ATH END NEABNK WLOH IN EMD AMR ER AFTSS HIN 3 | IHSERC RE AHTL HIN MRWA EINM SHNO SAW SRTIBG UD SO NGBA DNEI 4 | EIHSGTC ESISTH RAETV UD DEN LERNIOKG NITHC NDE LOENINKGRE TIM 5 | OKRN UDN CHWFSEI NEIM NSOH ES STI IEN BIFTRLSEEEN DU BILESE 6 | IKDN OMKM EHG MIT MIR RAG ECHNOS EPELSI EIPSL IHC ITM RDI 7 | HNCMA BEUTN MBLUNE DINS NA DEM TNDRAS NMIEE UTETMR AHT CAMHN 8 | UDNGEL GDAWEN MIEN EATRV MENI VEART DUN OSTHER DU CINTH SAW 9 | KNNOEIREGL RIM ILEES PRSTVRCIEH ISE IHGRU BEEILB RIGUH MNEI 10 | KNDI NI RDNEUR NATBRLET STAESUL EDR WNID 11 | 12 | 13 | 14 | DSNOACAIF ORP ANU DAEDALRI DNAAEIMTI EQU NNCOSETE EL RSTEOUL 15 | SMA AACTFAITNS UQE EL TSVAO OINSRVUE DE US ANIGIICANOM EIORDP 16 | TOOD RTEIENS RPO LE ITOABOLRROA ED QIUAMALI USOP A NSSRCAEAD 17 | LA TMREAAI NXTADAUEE ROP GOARLS EMESS DE NNAMICLUIAPO Y LOVOIV 18 | A RES LE RHMEOB EOMDNEERPRD DE LOS RSOPMRIE OMTSIPE UEQ 19 | CIIDADE LE RTDAAOZ ED LSA CELSAL Y LA NICOIOPS ED LAS UESVNA 20 | SSACA Y ES ITRMNEEOD QEU AERFU EL UEQIN IIIRDEGAR LA 21 | NAIORTREICP DE AL RRTEIA 22 | 23 | 24 | 25 | IMTRUESMME DNA TEH LNGIIV SI EYAS SIFH REA GJPNUIM DNA HET 26 | TTNOCO IS GHIH OH OUYR DDADY SI IRHC DAN ROUY MA SI DOGO 27 | GKOILON OS USHH LTLIET BBYA NDOT OUY CYR NEO OF HESET 28 | YUO RE NANGO SIER PU SNIGING NAD OULLY EPADRS YUOR GINSW 29 | DAN LYOLU KATE OT HET KSY TUB ITLL TATH MGNIRNO EREHT NATI 30 | INTGOHN ACN AHMR OYU TWIH DADYD NDA MYMMA NSTIDGAN YB 31 | -------------------------------------------------------------------------------- /turtle/coord.tikz: -------------------------------------------------------------------------------- 1 | \tikzstyle{line} = [draw,gray,thick] 2 | \tikzstyle{arrow} = [->,>=latex,thick] 3 | \begin{tikzpicture}%[scale=0.5] 4 | 5 | 6 | 7 | \draw[arrow,orange] (-5,0)--(5.5,0) node[below]{$x$}; 8 | \draw[arrow,blue] (0,-4.25)--(0,4.5) node[left]{$y$}; 9 | 10 | 11 | 12 | \foreach \x in {-4,-3,-2,-1,1,2,3,4} { 13 | \draw[orange] (\x,0.1)--++(0,-0.2) node[below,scale=0.7]{$\x00$}; 14 | } 15 | 16 | \foreach \y in {-3,-2,-1,1,2,3} { 17 | \draw[blue] (0.1,\y)--++(-0.2,0) node[left,scale=0.7]{$\y00$}; 18 | } 19 | 20 | \node[above right,scale=0.7] at (0,0) {$(0,0)$}; 21 | \fill (0,0) circle (2pt); 22 | 23 | \draw (-4.75,-4) rectangle (4.75,4); 24 | \end{tikzpicture} 25 | -------------------------------------------------------------------------------- /turtle/fig-turtle-5a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/fig-turtle-5a.png -------------------------------------------------------------------------------- /turtle/fig-turtle-5a.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \def\r{4}; 4 | \def\n{10}; 5 | \def\nn{9}; 6 | 7 | \draw[gray,ultra thick] (0,0) circle(\r cm); 8 | 9 | 10 | 11 | \foreach \i in {0,...,9}{ 12 | \draw[blue, very thick] (\i*360/\n:\r) -- (2*\i*360/\n:\r); 13 | } 14 | 15 | \foreach \i in {0,...,\nn}{ 16 | \fill[red] (\i*360/\n:\r) circle(4pt); 17 | \node at (\i*360/\n:\r+0.7) {\bf \i}; 18 | } 19 | 20 | \end{tikzpicture} -------------------------------------------------------------------------------- /turtle/fig-turtle-5c.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture} 2 | 3 | \draw[->,>=latex,ultra thick,gray] (-5,0)--(5,0) node[below]{$x$}; 4 | \draw[->,>=latex,ultra thick,gray] (0,-5)--(0,5) node[left]{$y$}; 5 | 6 | \def\r{4}; 7 | \def\n{7}; 8 | 9 | 10 | \draw[gray,ultra thick] (0,0) circle(\r cm); 11 | 12 | 13 | \foreach \i in {0,...,\n}{ 14 | \fill[red] (\i*360/\n:\r) circle(4pt); 15 | 16 | } 17 | 18 | 19 | \foreach \i in {0,1}{ 20 | \node[black,above right] at (\i*360/\n:\r){$(x_\i,y_\i)$} ; 21 | } 22 | 23 | 24 | \node[black,below right] at (-360/\n:\r){$(x_{n-1},y_{n-1})$} ; 25 | 26 | \coordinate (S) at (3*360/\n:\r); 27 | \node[black,above left] at (S) {$(x_{i},y_{i})$} ; 28 | \draw[dashed,very thick, blue] (S) -- (S |- 0,0) node[below] {$x_i = r\cos\left(\frac{2 i\pi}{n}\right)$}; 29 | \draw[dashed,very thick, blue] (S) -- (S -| 0,0) node[right] {$y_i = r\sin\left(\frac{2 i\pi}{n}\right)$}; 30 | 31 | 32 | \node[black,below right] at (0,0) {$(0,0)$} ; 33 | \draw[gray,very thick, below right] (0,0)--(-140:\r) node[midway, below right,black] {$r$} ; 34 | \end{tikzpicture} -------------------------------------------------------------------------------- /turtle/fig-turtle-6c.tikz: -------------------------------------------------------------------------------- 1 | \tikzstyle{line} = [draw,gray,very thick] 2 | \tikzstyle{arrow} = [->,>=latex,ultra thick] 3 | \begin{tikzpicture}[scale=0.5] 4 | 5 | \draw[line] (-5,-5) rectangle ++(10,10); 6 | \draw[arrow,red] (-5,-5) -- ++(3,0); 7 | \draw[arrow,green!60!black] (-5,5) -- ++(0,-3); 8 | \draw[arrow,orange] (5,5) -- ++(-3,0); 9 | \draw[arrow,blue] (5,-5) -- ++(0,3); 10 | 11 | \fill[red] (-5,-5) circle (7pt) node[below left, black] {turtle 1}; 12 | \fill[green!60!black] (-5,5) circle (7pt) node[above left, black] {turtle 4}; 13 | \fill[orange] (5,5) circle (7pt) node[above right, black] {turtle 3}; 14 | \fill[blue] (5,-5) circle (7pt) node[below right, black] {turtle 2}; 15 | 16 | \end{tikzpicture} 17 | -------------------------------------------------------------------------------- /turtle/screen-turtle-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-0.png -------------------------------------------------------------------------------- /turtle/screen-turtle-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-1.png -------------------------------------------------------------------------------- /turtle/screen-turtle-2a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-2a.png -------------------------------------------------------------------------------- /turtle/screen-turtle-2b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-2b.png -------------------------------------------------------------------------------- /turtle/screen-turtle-2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-2c.png -------------------------------------------------------------------------------- /turtle/screen-turtle-2d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-2d.png -------------------------------------------------------------------------------- /turtle/screen-turtle-3a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-3a.png -------------------------------------------------------------------------------- /turtle/screen-turtle-3b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-3b.png -------------------------------------------------------------------------------- /turtle/screen-turtle-4a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-4a.png -------------------------------------------------------------------------------- /turtle/screen-turtle-4b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-4b.png -------------------------------------------------------------------------------- /turtle/screen-turtle-4c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-4c.png -------------------------------------------------------------------------------- /turtle/screen-turtle-4d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-4d.png -------------------------------------------------------------------------------- /turtle/screen-turtle-5b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-5b.png -------------------------------------------------------------------------------- /turtle/screen-turtle-6a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-6a.png -------------------------------------------------------------------------------- /turtle/screen-turtle-6b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/screen-turtle-6b.png -------------------------------------------------------------------------------- /turtle/turtle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/turtle/turtle.pdf -------------------------------------------------------------------------------- /turtle/turtle_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Turtle 4 | ############################## 5 | 6 | ############################## 7 | # Activity 1 - Move your turtle! 8 | ############################## 9 | 10 | # Begining of the code 11 | 12 | from turtle import * 13 | 14 | width(5) # ize of the pencil 15 | 16 | # Letter "P" 17 | 18 | color('red') 19 | 20 | left(90) # 90 degree to the left 21 | forward(200) # Go ahead! 22 | 23 | right(90) 24 | forward(100) 25 | 26 | right(90) 27 | forward(100) 28 | 29 | right(90) 30 | forward(100) 31 | 32 | up() 33 | 34 | # End of the code 35 | 36 | # Letter "Y" 37 | 38 | color('blue') 39 | 40 | goto(200,0) 41 | down() 42 | setheading(90) 43 | forward(120) 44 | left(30) 45 | forward(75) 46 | backward(75) 47 | right(60) 48 | forward(75) 49 | 50 | exitonclick() 51 | -------------------------------------------------------------------------------- /turtle/turtle_2.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Turtle 4 | ############################## 5 | 6 | ############################## 7 | # Activity 2 - Loop "for" 8 | ############################## 9 | 10 | ############################## 11 | # Question 1 12 | 13 | from turtle import * 14 | 15 | # A pentagon 16 | width(5) 17 | color('blue') 18 | 19 | for i in range(5): 20 | forward(100) 21 | left(72) 22 | 23 | 24 | ############################## 25 | # Question 2 26 | 27 | # An other pentagon 28 | color('red') 29 | 30 | longueur = 200 31 | angle = 72 32 | for i in range(5): 33 | forward(longueur) 34 | left(angle) 35 | 36 | 37 | ############################## 38 | # Question 3 39 | 40 | # A dodecagon (12 edges) 41 | 42 | color("purple") 43 | n = 12 44 | angle = 360/n 45 | for i in range(n): 46 | forward(100) 47 | left(angle) 48 | 49 | 50 | ############################## 51 | # Question 4 52 | 53 | # A spiral 54 | 55 | color("green") 56 | length = 10 57 | for i in range(25): 58 | forward(length) 59 | left(40) 60 | length = length + 10 61 | 62 | exitonclick() 63 | 64 | 65 | -------------------------------------------------------------------------------- /turtle/turtle_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Turtle 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 3 - Graph of a function 9 | ############################## 10 | 11 | 12 | from turtle import * 13 | from math import * 14 | 15 | speed("fastest") 16 | width(2) 17 | color('blue') 18 | up() 19 | 20 | for x in range(-200,200): 21 | if x == -199: down() 22 | # y = 1/ 100 * x ** 2 # Parabola 23 | y = 100*sin(1/20*x) # Sine 24 | goto(x,y) 25 | 26 | 27 | exitonclick() 28 | 29 | -------------------------------------------------------------------------------- /turtle/turtle_4.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Turtle 4 | ############################## 5 | 6 | ############################## 7 | # Activity 4 - Nested "for" loop -Sierpinski triangle 8 | ############################## 9 | 10 | from turtle import * 11 | 12 | width(5) 13 | up() 14 | goto(-100,-100) 15 | down() 16 | 17 | for i in range(3): 18 | color("blue") 19 | forward(256) 20 | left(120) 21 | 22 | for i in range(3): 23 | color("red") 24 | forward(128) 25 | left(120) 26 | 27 | for i in range(3): 28 | color("green") 29 | forward(64) 30 | left(120) 31 | 32 | # for i in range(3): 33 | # color("orange") 34 | # forward(32) 35 | # left(120) 36 | 37 | exitonclick() 38 | 39 | -------------------------------------------------------------------------------- /turtle/turtle_5.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Turtle 4 | ############################## 5 | 6 | ############################## 7 | # Activity 5 - Multiplication tables 8 | ############################## 9 | 10 | from turtle import * 11 | from math import * 12 | 13 | speed("fastest") 14 | 15 | n = 100 16 | b = 2 17 | r = 200 18 | 19 | for i in range(n): 20 | up() 21 | goto(r*cos(2*i*pi/n),r*sin(2*i*pi/n)) 22 | down() 23 | j = (b*i) % n 24 | goto(r*cos(2*j*pi/n),r*sin(2*j*pi/n)) 25 | 26 | exitonclick() 27 | 28 | -------------------------------------------------------------------------------- /turtle/turtle_lesson.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Turtle 4 | ############################## 5 | 6 | ############################## 7 | # Lesson - Turtle 8 | ############################## 9 | 10 | from turtle import * 11 | 12 | forward(100) # Move forward 13 | left(90) # Turn 90 degrees left 14 | forward(50) 15 | width(5) # Width of the pencil 16 | forward(100) 17 | color('red') 18 | right(90) 19 | forward(200) 20 | 21 | exitonclick() 22 | 23 | ################# 24 | # Lesson - Several turtles 25 | ################# 26 | 27 | tortue1 = Turtle() # With capital 'T'! 28 | tortue2 = Turtle() 29 | 30 | tortue1.color('red') 31 | tortue2.color('blue') 32 | 33 | tortue1.forward(100) 34 | tortue2.left(90) 35 | tortue2.forward(100) -------------------------------------------------------------------------------- /while/conj_un_deux_un.sage: -------------------------------------------------------------------------------- 1 | # 2 | # For sagemath 3 | # 4 | # load("conj_un_deux_un.sage") 5 | ############################## 6 | # Conjecture 1211111... n'est jamais premier 7 | 8 | def un_deux_un(k): 9 | u = 12 10 | for i in range(k): 11 | u = 10*u + 1 12 | return u 13 | 14 | def test_premier_un_deux_un(kmax): 15 | for k in range(kmax): 16 | uk = un_deux_un(k) 17 | print(k,uk,is_prime(uk)) 18 | return 19 | 20 | 21 | # Test 22 | print("--- Test conj 121111.... jamais premier ---") 23 | 24 | test_premier_un_deux_un(140) 25 | 26 | print(factor(un_deux_un(34))) 27 | # 28 | 29 | -------------------------------------------------------------------------------- /while/fig-while-en.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=1.2, every node/.style={scale=1.2}] 2 | 3 | \draw[very thick] (0,0) -- (1,0); 4 | \draw[very thick] (0,-0.75) -- (0,0); 5 | 6 | \node[blue] at (0.5,0.4) {$q$}; 7 | \node[blue] at (0.5,-1.2) {$r$}; 8 | \node at (0.5,-0.4) {$a$}; 9 | \node at (-0.5,-0.4) {$b$}; 10 | 11 | \draw[<-,>=latex,ultra thick,blue] (0.6,0.4) to [bend right] (2,1) node[above right]{quotient}; 12 | \draw[<-,>=latex,ultra thick,blue] (0.4,-1.3) to [bend left] (-2,-1.2) node[above left]{remainder}; 13 | 14 | \begin{scope}[xshift=5cm] 15 | \draw[very thick] (0,0) -- (1,0); 16 | \draw[very thick] (0,-0.75) -- (0,0); 17 | 18 | \node[blue] at (0.5,0.4) {$14$}; 19 | \node[blue] at (0.5,-1.2) {$2$}; 20 | \node at (0.5,-0.4) {$100$}; 21 | \node at (-0.5,-0.4) {$7$}; 22 | \end{scope} 23 | 24 | \end{tikzpicture} -------------------------------------------------------------------------------- /while/fig-while-lesson.tikz: -------------------------------------------------------------------------------- 1 | \usetikzlibrary{positioning} 2 | \begin{tikzpicture}[scale=1, every node/.style={transform shape}] 3 | \Large 4 | \node[right] (A) at (0,0) {\texttt{while}}; 5 | \node[right,right=-0.7em of A] (B) {\texttt{condition}}; 6 | \node[right,right=-0.8em of B] (C) {\texttt{:}}; 7 | 8 | 9 | \node[right] (E) at (1,-0.7) {\texttt{instruction\_1}}; 10 | \node[right] at (1,-1.4) {\texttt{instruction\_2}}; 11 | \node[right] at (1,-2.1) {\texttt{...}}; 12 | \node[right] (F) at (0,-2.8) {\texttt{other instructions}}; 13 | 14 | \draw[<-,>=latex,ultra thick, red] (A.north) to[bend left] (9,3) node[right] {keyword "\texttt{while}"}; 15 | \draw[<-,>=latex,ultra thick, red] (B.north) to[bend left] (9,2) node[right] {a condition}; 16 | \draw[<-,>=latex,ultra thick, red] (C.north) to[bend left] (9,1) node[right] {colon}; 17 | 18 | \draw[|-|,ultra thick, red] (5.5,-0.3)--++(0,-2.1); 19 | \draw[ultra thick, red] (5.5,-1.2) to[bend right] (10,-0.5) node[right] {indented block will}; 20 | \node[right,red] at (10,-1.25) {be executed as long as}; 21 | \node[right,red] at (10,-1.9) {the condition is true}; 22 | 23 | \draw[<-,>=latex,ultra thick, red] (F.east) to[bend left] (9,-3.2) node[right] {program continuation}; 24 | 25 | \end{tikzpicture} -------------------------------------------------------------------------------- /while/fig-while.tikz: -------------------------------------------------------------------------------- 1 | \begin{tikzpicture}[scale=1.2, every node/.style={scale=1.2}] 2 | 3 | \draw[very thick] (0,0) -- (1,0); 4 | \draw[very thick] (0,-1.25) -- (0,0.75); 5 | 6 | \node at (0.5,0.4) {$b$}; 7 | \node at (-0.5,0.4) {$a$}; 8 | \node[blue] at (0.5,-0.4) {$q$}; 9 | \node[blue] at (-0.5,-0.4) {$r$}; 10 | 11 | \draw[<-,>=latex,ultra thick,blue] (0.6,-0.6) to [bend right] (2,-1) node[right]{quotient}; 12 | \draw[<-,>=latex,ultra thick,blue] (-0.6,-0.6) to [bend left] (-2,-1) node[left]{remainder}; 13 | 14 | \begin{scope}[xshift=5cm] 15 | \draw[very thick] (0,0) -- (1,0); 16 | \draw[very thick] (0,-1.25) -- (0,0.75); 17 | 18 | \node at (0.5,0.4) {$7$}; 19 | 20 | \node at (-0.5,0.4) {$100$}; 21 | \node[blue] at (0.5,-0.4) {$14$}; 22 | \node[blue] at (-0.5,-0.4) {$2$}; 23 | \end{scope} 24 | 25 | \end{tikzpicture} -------------------------------------------------------------------------------- /while/while-1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/while/while-1.pdf -------------------------------------------------------------------------------- /while/while-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exo7math/python1-en-exo7/a4605b8e5cf56d20d99beb50305865ab225021d1/while/while-2.pdf -------------------------------------------------------------------------------- /while/while_3.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # While - Boolean - Arithmetic 4 | ############################## 5 | 6 | 7 | ############################## 8 | # Activity 3 - Divisor, prime numbers - Loop while (continued) 9 | ############################## 10 | 11 | 12 | ############################## 13 | # Reminders from activity 2 14 | 15 | def is_prime(n): 16 | """ Test if n is a prime number """ 17 | if n < 2: return False 18 | if n == 2: return True 19 | if n % 2 == 0: return False 20 | 21 | d = 3 22 | while (n % d != 0) and (d**2 <= n): 23 | d = d + 2 24 | 25 | if d ** 2 > n: 26 | return True 27 | else: 28 | return False 29 | 30 | ############################## 31 | ############################## 32 | 33 | 34 | ############################## 35 | ## Question 1 ## 36 | 37 | def prime_number_after(n): 38 | """ Look for the first prime number after n """ 39 | p = n 40 | while not is_prime(p): 41 | p = p + 1 42 | return p 43 | 44 | 45 | # Test 46 | print("--- First prime number after an intger ---") 47 | print(prime_number_after(60)) 48 | print(prime_number_after(100000)) 49 | 50 | 51 | ############################## 52 | ## Question 2 ## 53 | 54 | def twin_prime_after(n): 55 | """ Find twin primes after n """ 56 | p = n 57 | q = p + 2 58 | while (not is_prime(p)) or (not is_prime(q)): 59 | p = p + 1 60 | q = p + 2 61 | return p,q 62 | 63 | 64 | # Test 65 | print("--- First twin primes after an integer ---") 66 | print(twin_prime_after(60)) 67 | print(twin_prime_after(100000)) 68 | 69 | 70 | ############################## 71 | ## Question 3 ## 72 | 73 | def germain_prime_after(n): 74 | """ Find two Germain primes after n """ 75 | p = n 76 | q = 2*p + 1 77 | while (not is_prime(p)) or (not is_prime(q)): 78 | p = p + 1 79 | q = 2*p + 1 80 | return p,q 81 | 82 | 83 | # Test 84 | print("--- First Germain primes after an integer ---") 85 | print(germain_prime_after(60)) 86 | print(germain_prime_after(100000)) 87 | 88 | 89 | -------------------------------------------------------------------------------- /while/while_lesson_1.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # Tant que - Booléen - Arithmétiques 4 | ############################## 5 | 6 | ############################## 7 | # Cours 1 8 | ############################## 9 | 10 | 11 | n = 10 12 | while n >= 0: 13 | print(n) 14 | n = n - 1 15 | 16 | 17 | n = 100 18 | p = 1 19 | while p < n: 20 | p = 2*p 21 | print(p) 22 | 23 | 24 | def est_paire(n): 25 | return n%2 == 0 26 | 27 | 28 | n = 56 29 | while est_paire(n) == True: 30 | n = n // 2 31 | print(n) -------------------------------------------------------------------------------- /while/while_lesson_2.py: -------------------------------------------------------------------------------- 1 | 2 | ############################## 3 | # While II 4 | ############################## 5 | 6 | ############################## 7 | # Lesson 2 - break 8 | ############################## 9 | 10 | ############################## 11 | # Example 1 12 | 13 | # Countdown 14 | n = 10 15 | while True: # Infinite loop 16 | print(n) 17 | n = n - 1 18 | if n < 0: 19 | break # Immediate stop 20 | 21 | # Better (with a flag) 22 | n = 10 23 | finished = False 24 | while not finished: 25 | print(n) 26 | n = n - 1 27 | if n < 0: 28 | finished = True 29 | 30 | # Even better (after reformulation) 31 | n = 10 32 | while n >= 0: 33 | print(n) 34 | n = n - 1 35 | 36 | ############################## 37 | # Example 2 38 | 39 | # Integer square root 40 | n = 777 41 | for i in range(100): 42 | if i**2 > n: 43 | break 44 | print(i-1) 45 | 46 | 47 | # Better 48 | n = 777 49 | i = 0 50 | while i**2 <= n: 51 | i = i + 1 52 | print(i-1) 53 | 54 | 55 | ############################## 56 | # Example 3 57 | 58 | from math import * 59 | 60 | # Square root of the elements of a list 61 | mylist = [3,7,0,10,-1,12] 62 | for element in mylist: 63 | if element < 0: 64 | break 65 | print(sqrt(element)) 66 | 67 | 68 | # Better with try/except 69 | mylist = [3,7,0,10,-1,12] 70 | for element in mylist: 71 | try: 72 | print(sqrt(element)) 73 | except: 74 | print("Warning, I don't know have to compute the square root of",element) 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /while/while_lesson_timeit.py: -------------------------------------------------------------------------------- 1 | # First function (not very clever) 2 | def my_function_1(n): 3 | divis = False 4 | for k in range(n): 5 | if k*7 == n: 6 | divis = True 7 | return divis 8 | 9 | # Second function (faster) 10 | def my_function_2(n): 11 | if n % 7 == 0: 12 | return True 13 | else: 14 | return False 15 | 16 | # Measurement of execution times 17 | import timeit 18 | 19 | print(timeit.timeit("my_function_1(1000)", 20 | setup="from __main__ import my_function_1", 21 | number=100000)) 22 | print(timeit.timeit("my_function_2(1000)", 23 | setup="from __main__ import my_function_2", 24 | number=100000)) 25 | --------------------------------------------------------------------------------