├── .gitignore ├── Fiches ├── Les commandes du Terminal │ ├── README.md │ ├── commande-cd-01.png │ ├── commande-cd-02.png │ ├── commande-ls-01.png │ ├── commande-ls-02.png │ ├── commande-ls-03.png │ ├── commande-mkdir.png │ ├── commande-pwd.png │ ├── commande-rm.png │ └── commande-touch.png ├── Les opérateurs mathématiques │ └── README.md └── Les variables │ └── README.md ├── README.md ├── Section 10 ├── Exercice 1 │ ├── 01-sources │ │ └── recuperer_input.py │ └── 02-solution │ │ └── recuperer_input.py ├── Exercice 2 │ ├── 01-sources │ │ └── changer_type_variable.py │ └── 02-solution │ │ └── changer_type_variable.py ├── Session 50 │ └── script.py ├── Session 52 │ └── script.py ├── Session 53 │ └── script.py └── Session 54 │ └── script.py ├── Section 11 ├── Exercice 3 │ ├── 01-sources │ │ └── la_calculatrice_01.py │ └── 02-solution │ │ └── la_calculatrice_01.py └── Exercice 4 │ ├── 01-sources │ └── la_concatenation.py │ └── 02-solution │ └── la_concatenation.py ├── Section 14 └── Exercice 5 │ ├── 01-sources │ └── devine_un_nombre_01.py │ └── 02-solution │ └── devine_un_nombre_01.py ├── Section 15 ├── Session 64 │ └── script.py ├── Session 65 │ └── script.py ├── Session 66 │ └── script.py └── Session 67 │ └── script.py ├── Section 17 └── Exercice 7 │ ├── 01-sources │ └── devine_un_nombre_02.py │ └── 02-solution │ └── devine_un_nombre_02.py ├── Section 18 ├── Session 76 │ └── script.py ├── Session 77 │ └── script.py └── Session 78 │ └── script.py ├── Section 19 └── Exercice 8 │ ├── 01-sources │ └── devine_un_nombre_03.py │ └── 02-solution │ └── devine_un_nombre_03.py ├── Section 20 ├── Session 80 │ └── script.py ├── Session 82 │ └── script.py ├── Session 83 │ └── script.py ├── Session 85 │ └── script.py ├── Session 87 │ └── script.py ├── Session 88 │ └── script.py ├── Session 89 │ └── script.py ├── Session 90 │ └── script.py └── Session 91 │ └── script.py ├── Section 21 └── Exercice 9 │ ├── solution │ └── script.py │ └── sources │ └── script.py ├── Section 22 └── Exercice 10 │ ├── 01-sources │ └── devine_un_nombre_04.py │ └── 02-solution │ └── devine_un_nombre_04.py ├── Section 23 └── Exercice 11 │ ├── 01-sources │ └── comprehension_de_liste.py │ └── 02-solutions │ └── comprehension_de_liste.py.py ├── Section 24 ├── Exercice 12 │ ├── 01-sources │ │ └── afficher_utilisateurs.py │ └── 02-solution │ │ └── afficher_utilisateurs.py ├── Exercice 13 │ ├── 01-sources │ │ └── afficher_un_mot_a_lenvers.py │ └── 02-solution │ │ └── afficher_un_mot_a_lenvers.py └── Exercice 14 │ ├── 01-sources │ └── sortir_boucle_while.py │ └── 02-solution │ └── sortir_boucle_while.py ├── Section 25 └── Exercice 15 │ ├── 01-sources │ └── devine_un_nombre_05.py │ └── 02-solution │ └── devine_un_nombre_05.py ├── Section 28 ├── Exercice 16 │ ├── 01-sources │ │ └── la_liste_de_courses_01.py │ └── 02-solutions │ │ └── la_liste_de_courses_01.py ├── Exercice 17 │ ├── 01-sources │ │ └── la_liste_de_courses_02.py │ └── 02-solutions │ │ └── la_liste_de_courses_02.py ├── Exercice 18 │ ├── 01-sources │ │ └── la_liste_de_courses_03.py │ └── 02-solutions │ │ └── la_liste_de_courses_03.py ├── Exercice 19 │ ├── 01-sources │ │ └── la_liste_de_courses_04.py │ └── 02-solutions │ │ └── la_liste_de_courses_04.py └── Exercice 20 │ ├── 01-sources │ └── la_liste_de_courses_05.py │ └── 02-solutions │ └── la_liste_de_courses_05.py ├── Section 30 ├── Exercice 21 │ ├── 01-sources │ │ └── structure_dossier.py │ └── 02-solution │ │ └── structure_dossier.py ├── Exercice 22 │ ├── 01-sources │ │ ├── chercher_un_mot.py │ │ └── dossier_exemple │ │ │ ├── administratif │ │ │ ├── adresses.json │ │ │ ├── comptes_bancaires.json │ │ │ └── securite_sociale.txt │ │ │ ├── images │ │ │ ├── chat_01.jpg │ │ │ ├── chat_02.jpeg │ │ │ ├── chat_03.jpg │ │ │ ├── chat_04.jpg │ │ │ ├── chien_01.jpeg │ │ │ ├── chien_02.jpg │ │ │ ├── chien_03.jpg │ │ │ ├── chien_04.jpg │ │ │ └── chien_05.jpg │ │ │ └── notes │ │ │ └── notes_diverses.txt │ └── 02-solution │ │ ├── chercher_un_mot.py │ │ └── dossier_exemple │ │ ├── administratif │ │ ├── adresses.json │ │ ├── comptes_bancaires.json │ │ └── securite_sociale.txt │ │ ├── images │ │ ├── chat_01.jpg │ │ ├── chat_02.jpeg │ │ ├── chat_03.jpg │ │ ├── chat_04.jpg │ │ ├── chien_01.jpeg │ │ ├── chien_02.jpg │ │ ├── chien_03.jpg │ │ ├── chien_04.jpg │ │ └── chien_05.jpg │ │ └── notes │ │ └── notes_diverses.txt └── Exercice 23 │ ├── 01-sources │ ├── chercher_un_mot.py │ └── dossier_exemple │ │ ├── administratif │ │ ├── adresses.json │ │ ├── comptes_bancaires.json │ │ └── securite_sociale.txt │ │ ├── images │ │ ├── chat_01.jpg │ │ ├── chat_02.jpeg │ │ ├── chat_03.jpg │ │ ├── chat_04.jpg │ │ ├── chien_01.jpeg │ │ ├── chien_02.jpg │ │ ├── chien_03.jpg │ │ ├── chien_04.jpg │ │ └── chien_05.jpg │ │ └── notes │ │ └── notes_diverses.txt │ └── 02-solution │ ├── chercher_un_mot.py │ └── dossier_exemple │ ├── administratif │ ├── adresses.json │ ├── comptes_bancaires.json │ └── securite_sociale.txt │ ├── images │ ├── chat_01.jpg │ ├── chat_02.jpeg │ ├── chat_03.jpg │ ├── chat_04.jpg │ ├── chien_01.jpeg │ ├── chien_02.jpg │ ├── chien_03.jpg │ ├── chien_04.jpg │ └── chien_05.jpg │ └── notes │ └── notes_diverses.txt ├── Section 31 └── Exercice 24 │ ├── 01-sources │ ├── fichier_invalide.abc │ └── readme.txt │ └── 02-solution │ ├── fichier_invalide.abc │ ├── gerer_erreurs.py │ └── readme.txt ├── Section 33 ├── Session 127 │ ├── random.py │ └── script.py ├── Session 128 │ ├── script.py │ └── utils.py ├── Session 129 │ └── script.py └── Session 133 │ ├── script.py │ └── utils.py ├── Section 36 ├── Session 139 │ └── script.py ├── Session 140 │ └── script.py └── Session 141 │ └── script.py ├── Section 39 ├── Session 156 │ └── classe.py ├── Session 157 │ └── instances.py ├── Session 158 │ └── attributs.py ├── Session 159 │ └── initialisation.py ├── Session 161 │ └── self.py └── Session 163 │ └── script.py ├── Section 40 └── Exercice 25 │ └── voiture.py ├── Section 41 ├── Session 166 │ └── constants.py ├── Session 167 │ ├── constants.py │ └── lib.py ├── Session 168 │ ├── constants.py │ └── lib.py ├── Session 169 │ ├── constants.py │ └── lib.py └── Session 170 │ ├── constants.py │ ├── data │ └── courses.json │ └── lib.py ├── Section 42 ├── Session 170 │ └── polymorphisme.py ├── Session 171 │ └── class_method.py ├── Session 172 │ └── static_method.py ├── Session 173 │ └── method_magic.py ├── Session 174 │ └── heritage.py ├── Session 175 │ └── super.py └── Session 176 │ └── surcharge.py ├── Section 43 ├── Session 179 │ ├── app.py │ └── settings.json ├── Session 180 │ ├── app.py │ └── database.db ├── Session 181 │ ├── app.py │ └── database.db ├── Session 183 │ ├── app.py │ └── database.db ├── Session 184 │ ├── app.py │ └── database.db ├── Session 185 │ ├── app.py │ └── database.db └── Session 186 │ ├── app.py │ └── database.db ├── Section 45 ├── Session 192 │ └── app.py ├── Session 193 │ └── app.py ├── Session 194 │ └── app.py ├── Session 195 │ └── app.py ├── Session 196 │ └── app.py ├── Session 197 │ └── app.py └── Session 198 │ └── app.py ├── Section 46 ├── Session 202 │ ├── app.py │ ├── data │ │ └── movies.json │ └── movie.py ├── Session 206 │ ├── app.py │ ├── data │ │ └── movies.json │ └── movie.py ├── Session 208 │ ├── app.py │ ├── data │ │ └── movies.json │ └── movie.py ├── Session 210 │ ├── app.py │ ├── data │ │ └── movies.json │ └── movie.py ├── Session 212 │ ├── app.py │ ├── data │ │ └── movies.json │ └── movie.py └── Session 214 │ ├── app.py │ ├── data │ └── movies.json │ └── movie.py └── Section 47 ├── Session 216 ├── app.py ├── data │ └── movies.json └── movie.py ├── Session 218 ├── app.py ├── data │ └── movies.json └── movie.py ├── Session 220 ├── app.py ├── data │ └── movies.json └── movie.py ├── Session 222 ├── app.py ├── data │ └── movies.json └── movie.py └── Session 223 ├── app.py ├── data └── movies.json └── movie.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | .idea/ 12 | .DS_Store 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | .pytest_cache/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Django stuff: 57 | *.log 58 | local_settings.py 59 | db.sqlite3 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # Environments 87 | .env 88 | .venv 89 | env/ 90 | venv/ 91 | ENV/ 92 | env.bak/ 93 | venv.bak/ 94 | 95 | # Spyder project settings 96 | .spyderproject 97 | .spyproject 98 | 99 | # Rope project settings 100 | .ropeproject 101 | 102 | # mkdocs documentation 103 | /site 104 | 105 | # mypy 106 | .mypy_cache/ 107 | -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/README.md: -------------------------------------------------------------------------------- 1 | # Les commandes du Terminal 2 | 3 | Il existe des centaines de commandes bash différentes que vous pouvez utiliser à l'intérieur de votre Terminal. Voici 6 commandes couramment utilisées pour naviguer dans votre système d'exploitation et créer des fichiers et dossiers : 4 | 5 | ### La commande ls 6 | 7 | Cette commande permet de **l**i**s**ter les fichiers et dossiers qui se trouvent dans le répertoire courant : 8 | 9 | ![](commande-ls-01.png) 10 | 11 | Pour une vue en liste, vous pouvez utiliser le flag `-l` 12 | 13 | ![](commande-ls-02.png) 14 | 15 | Pour afficher les fichiers et dossiers cachés, vous pouvez également ajouter le flag `-a` 16 | 17 | ![](commande-ls-03.png) 18 | 19 | ### La commande cd 20 | 21 | Cette commande permet de naviguer à l'intérieur de la structure de dossier de votre système d'exploitation. Pour cela, il suffit de suivre cette commande du nom du dossier dans lequel vous souhaitez naviguer. Par exemple, pour entrer à l'intérieur du dossier `dossier_test` : 22 | 23 | ![](commande-cd-01.png) 24 | 25 | Pour remonter dans le dossier parent, vous pouvez utiliser la notation `..` qui représente le dossier parent du dossier dans lequel vous vous trouvez : 26 | 27 | ![](commande-cd-02.png) 28 | 29 | ### La commande pwd 30 | 31 | Cette commande permet tout simplement d'afficher le chemin du dossier courant. Pas grand chose de plus à dire : 32 | 33 | ![](commande-pwd.png) 34 | 35 | ### La commande clear 36 | 37 | Cette commande permet d'effacer les commandes précédemment exécutées dans le terminal. Pratique pour faire du ménage et y voir un peu plus clair 🤓 38 | 39 | ### La commande mkdir 40 | 41 | Cette commande permet de créer un dossier à l'intérieur du dossier courant. Il suffit de suivre cette commande du nom du dossier que vous souhaitez créer. Si vous êtes dans un endroit sur votre ordinateur qui nécessite des droits d'administrateurs, il se peut que vous ayez besoin de précéder cette commande de `sudo` afin de l'exécuter avec des droits élevés (votre mot de passe administrateur vous sera demandé). 42 | 43 | ![](commande-mkdir.png) 44 | 45 | ### La commande touch 46 | 47 | Cette commande permet, elle, de créer un fichier ! N'oubliez pas d'indiquer l'extension du fichier que vous souhaitez créer, bash ne la devinera pas tout seul ! 48 | 49 | ![](commande-touch.png) 50 | 51 | ### La commande rm 52 | 53 | Pour finir, cette commande permet tout simplement de supprimer un fichier ou un dossier. ⚠️ Pour supprimer un dossier, vous devez ajouter le flag `-r` : 54 | 55 | ![](commande-rm.png) -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-cd-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-cd-01.png -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-cd-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-cd-02.png -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-ls-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-ls-01.png -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-ls-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-ls-02.png -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-ls-03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-ls-03.png -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-mkdir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-mkdir.png -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-pwd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-pwd.png -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-rm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-rm.png -------------------------------------------------------------------------------- /Fiches/Les commandes du Terminal/commande-touch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Fiches/Les commandes du Terminal/commande-touch.png -------------------------------------------------------------------------------- /Fiches/Les opérateurs mathématiques/README.md: -------------------------------------------------------------------------------- 1 | # Les opérateurs mathématiques 2 | 3 | Il existe 4 opérateurs mathématiques de base en Python : 4 | 5 | - \+ (addition) 6 | - \- (soustraction) 7 | - / (division) 8 | - \* (multiplication) 9 | 10 | Pas besoin de beaucoup d'explications pour ces opérateurs. À savoir que vous pouvez utiliser certains de ces opérateurs sur des chaînes de caractères ! Par exemple : 11 | ```python 12 | >>> "Hello" * 3 13 | "HelloHelloHello" 14 | ``` 15 | 16 | Cela peut être pratique si par exemple vous souhaitez rapidement afficher une ligne de séparation : 17 | ```python 18 | >>> "-" * 50 19 | -------------------------------------------------- 20 | ``` 21 | 22 | Il existe également 3 opérateurs un peu plus avancés : 23 | 24 | - % (appelé 'modulo') 25 | - // (division entière) 26 | - ** (puissance) 27 | 28 | L'opérateur modulo retourne le reste de la division, par exemple : 29 | ```python 30 | >>> 10 % 5 31 | 0 32 | >>> 11 % 5 33 | 1 34 | ``` 35 | 36 | Dans le cas de figure ci-dessus, la division de 10 par 5 est égale à 2 et il reste 0. L'opérateur modulo retourne donc 0. 37 | 38 | Dans le deuxième cas de figure, la division de 11 par 5 donne un reste de 1, qui est donc retournée par le modulo. 39 | 40 | La division entière permet d'effectuer une division qui nous retournera toujours un nombre entier. Par exemple : 41 | ```python 42 | >>> 10 / 3 43 | 3.3333333333333 44 | >>> 10 // 3 45 | 3 46 | ``` 47 | 48 | À noter qu'avec une division normale, même si le compte est rond, la division vous retournera un nombre décimal : 49 | ```python 50 | >>> 10 / 5 51 | 2.0 52 | ``` 53 | 54 | Ainsi, si vous souhaitez toujours récupérer un nombre entier, passez par la division entière. 55 | 56 | Pour finir, l'opérateur puissance permet tout simplement d'effectuer un calcul du type 'a puissance n' : 57 | ```python 58 | >>> 2 ** 2 59 | 4 60 | >>> 2 ** 4 61 | 16 62 | ``` 63 | 64 | ## Pour résumer : 65 | 66 | Il existe en tout 7 opérateurs mathématiques, 4 de base (+, -, /, *) et 3 opérateurs avancés (%, //, **). Ces opérateurs permettent d'effectuer différentes opérations mathématiques, la plupart du temps sur des nombres, mais aussi dans certain cas sur des chaînes de caractères. 67 | 68 | ⚠️ Ne vous trompez pas pour l'opérateur de la multiplication, il s'agit bien du symbole 'astérisque' (*) et non pas de la lettre 'x'. Si vous essayez de faire `5 x 10` avec Python, vous aurez une erreur de syntaxe. 69 | 70 | ## Le module math 71 | Si vous avez besoin d'effectuer des calculs mathématiques plus complexes, vous devrez utiliser le module math car pour ne pas trop surcharger les fonctions disponibles par défaut, Python ne charge pas toutes ces fonctions de base quand vous lancez un interpréteur. 72 | 73 | Pour utiliser le module math, il faut l'importer comme ceci : 74 | ```python 75 | import math 76 | ``` 77 | 78 | Une fois le module importé, vous pouvez utiliser toutes les fonctions contenues à l'intérieur du module, en préfixant la fonction du nom du module. Par exemple pour calculer une racine carrée : 79 | ```python 80 | >>> racine = math.sqrt(16) 81 | >>> print(racine) 82 | 4.0 83 | ``` 84 | 85 | Ci-dessous, vous trouverez une liste non-exhaustive des fonctions les plus utilisés et disponibles dans le module math : 86 | 87 | - math.ceil(-4.7) : entier immédiatement supérieur, donne ici -4. 88 | - math.exp(2) : exponentielle. 89 | - math.factorial(5) : factorielle 5, donc 120 ici (fonctionne uniquement pour les entiers positifs). 90 | - math.floor(-4.7) : partie entière, donne ici -5. 91 | - math.isinf(x) : teste si x est infini (inf) et renvoie True si c'est le cas. 92 | - math.log(2) : logarithme en base naturelle. 93 | - math.log(8, 2) : log de 8 en base 2. 94 | - math.log10(2) : logarithme en base 10. 95 | - math.pow(2, 3) : 2 puissance 3 (peut aussi s'écrire 2 ** 3). 96 | - math.sqrt(16) : racine carrée, donne ici 4. 97 | - fonctions trigonométriques : math.sin, math.cos, math.tan, math.asin, math.acos, math.atan (argument en radians). 98 | - fonctions hyperboliques : math.sinh, math.cosh, math.tanh, math.asinh, math.acosh, math.tanh. 99 | - math.degrees(x) : convertit de radians en degrés. 100 | - math.radians(x) : convertit de degrés en radians. 101 | 102 | ### Les constantes : 103 | - math.pi (3.14159...) 104 | - math.e (2.71828...) 105 | -------------------------------------------------------------------------------- /Fiches/Les variables/README.md: -------------------------------------------------------------------------------- 1 | # Les variables 2 | 3 | ## Différents types 4 | 5 | Avec Python, vous pouvez utiliser différents types de variables, tels que les nombres entiers, les nombres décimaux ou encore les chaînes de caractères. 6 | 7 | ## Créer une variable 8 | 9 | Pour créer une variable, c'est très simple, il suffit de lui donner un nom et une valeur, comme ceci : 10 | ```python 11 | a = 5 12 | ``` 13 | 14 | ☝️ Ci-dessus, on créé une variable que l'on appelle `a` et qui contient le **nombre entier** `5`. 15 | 16 | ### Quelques règles à suivre 17 | 18 | Pour nommer une variable, il y a quelques règles que vous devez suivre, au risque de vous retrouver avec une erreur : 19 | 20 | - Le nom d'une variabe doit commencer par **une lettre** ou un **tiret du bas.** 21 | - Le nom d'une variable ne peut contenir que des **lettres**, des **nombres** et des **tirets du bas**. 22 | 23 | Vous pouvez donc inclure des nombres dans le nom des variables, tant qu'il ne sont **pas au début** du nom. Vous ne pouvez par contre inclure **aucun symbole** (pas de @$%* etc). 24 | 25 | Également, le nom des variables est sensible à la casse. Ainsi, `ville`, `Ville` et `VILLE` sont considérés par Python comme trois variables différentes. 26 | 27 | ### Convention PEP-8 28 | 29 | Selon les conventions de la PEP-8, il est conseillé de nommer vos variables uniquement avec des lettres minuscules en séparant les différents mots par un tiret du bas. 30 | 31 | Les trois noms de variabe suivant sont tous valides, mais on préférera utiliser le premier : 32 | 33 | ✅ nom_de_famille 34 | ⚠️ NomDeFamille 35 | ⚠️ nomdefamille 36 | 37 | Pour vous donner quelques exemples, voici une liste de noms de variables qui sont valides (✅), valides mais qui ne suivent pas la convention PEP-8 (⚠️) et invalides (🛑) : 38 | 39 | ✅ site_web 40 | ⚠️ NomDeLaVille 41 | 🛑 5_employes 42 | ✅ adresse_email 43 | ⚠️ Salaire 44 | 🛑 @dresseEmail 45 | ✅ taux_horaire 46 | 47 | ## Les mots réservés 48 | 49 | Python utilise des noms qui sont réservés par le langage pour décrire certains comportements. Vous ne pouvez donc pas utiliser ces mots réservés comme nom de variable. Voici la liste des mots réservés par Python : 50 | ```python 51 | False 52 | class 53 | finally 54 | is 55 | return 56 | None 57 | continue 58 | for 59 | lambda 60 | try 61 | True 62 | def 63 | from 64 | nonlocal 65 | while 66 | and 67 | del 68 | global 69 | not 70 | with 71 | as 72 | elif 73 | if 74 | or 75 | yield 76 | assert 77 | else 78 | import 79 | pass 80 | break 81 | except 82 | in 83 | raise 84 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # La Formation Complète Python 2 | Ce repo Github contient toutes les sources du cours [**La Formation Complète Python**](https://www.udemy.com/course/formation-complete-python/?referralCode=A8718FD55B87B8DECF6F). 3 | 4 | ## Fiches de révision 5 | Plusieurs fiches de révision sont à votre disposition pour pouvoir facilement revoir certaines notions abordées pendant la formation. 6 | 7 | - [Les commandes du terminal](Fiches/Les%20commandes%20du%20Terminal/README.md) 8 | - [Les variables](Fiches/Les%20variables/README.md) 9 | - [Les opérateurs mathématiques](Fiches/Les%20opérateurs%20mathématiques/README.md) 10 | -------------------------------------------------------------------------------- /Section 10/Exercice 1/01-sources/recuperer_input.py: -------------------------------------------------------------------------------- 1 | # Demander le prénom, la ville de naissance et l'âge de la personne qui utilise le script 2 | # Afficher ces trois informations -------------------------------------------------------------------------------- /Section 10/Exercice 1/02-solution/recuperer_input.py: -------------------------------------------------------------------------------- 1 | prenom = input("Comment vous appelez-vous ? ") 2 | ville_de_naissance = input("Quelle est votre ville de naissance ? ") 3 | age = input("Quel est votre âge ? ") 4 | 5 | print(prenom) 6 | print(ville_de_naissance) 7 | print(age) -------------------------------------------------------------------------------- /Section 10/Exercice 2/01-sources/changer_type_variable.py: -------------------------------------------------------------------------------- 1 | # Demander à l'utilisateur d'entrer un nombre 2 | # Afficher le résultat de l'addition de ce nombre avec le nombre a. 3 | # Par exemple : "Le résultat de l'opération est 15" (dans le cas où l'utilisateur entre le nombre 5) 4 | 5 | a = 10 -------------------------------------------------------------------------------- /Section 10/Exercice 2/02-solution/changer_type_variable.py: -------------------------------------------------------------------------------- 1 | a = 10 2 | b = input("Entrez un nombre : ") 3 | resultat = a + int(b) 4 | print("Le résultat de l'opération est " + str(resultat)) 5 | -------------------------------------------------------------------------------- /Section 10/Session 50/script.py: -------------------------------------------------------------------------------- 1 | nombre = input("Entrez un nombre: ") 2 | print(nombre) -------------------------------------------------------------------------------- /Section 10/Session 52/script.py: -------------------------------------------------------------------------------- 1 | b = "10" 2 | b = int(b) -------------------------------------------------------------------------------- /Section 10/Session 53/script.py: -------------------------------------------------------------------------------- 1 | nombre = input("Entrez un nombre: ") 2 | print(type(nombre)) # retourne . La fonction input retourne toujours une chaîne de caractères. 3 | 4 | # Vous pouvez par la suite convertir la variable nombre en nombre entier grâce à la fonction int 5 | nombre = int(nombre) 6 | print(type(nombre)) # retourne . La variable a bien été convertie. -------------------------------------------------------------------------------- /Section 10/Session 54/script.py: -------------------------------------------------------------------------------- 1 | a = 5 2 | b = 10 3 | resultat = f"La multiplication de {a} par {b} est égale à {a * b}." -------------------------------------------------------------------------------- /Section 11/Exercice 3/01-sources/la_calculatrice_01.py: -------------------------------------------------------------------------------- 1 | # Demander à l'utilisateur d'entrer un premier nombre 2 | # Demander à l'utilisateur d'entrer un deuxième nombre 3 | # Afficher à l'écran le résultat de l'addition (exemple : 'Le résultat de l'addition de 5 + 10 est égal à 15') -------------------------------------------------------------------------------- /Section 11/Exercice 3/02-solution/la_calculatrice_01.py: -------------------------------------------------------------------------------- 1 | a = input("Entrez un premier nombre : ") 2 | b = input("Entrez un deuxième nombre : ") 3 | resultat = f"Le résultat de l'addition de {a} avec {b} est égal à {a + b}" 4 | print(resultat) -------------------------------------------------------------------------------- /Section 11/Exercice 4/01-sources/la_concatenation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dans cet exercice, vous devez utiliser les fonctions de conversions 3 | pour convertir les objets dans le bon type afin d'afficher les phrases 4 | suivantes et éviter les erreurs. 5 | 6 | Phrases à afficher : 7 | J'ai une classe de 30 élèves 8 | 10 + 5 est égal à 15 9 | 15 10 | L'addition de 10 + 5 est égal à 15 11 | """ 12 | 13 | a = "J'ai une classe de " + 30 + " élèves" 14 | b = 10 + " + " + "5" + " est égal à " + 15 15 | c = 10 + "5" 16 | d = "L'addition de 10 + 5 est égal à " + 10 + 5 -------------------------------------------------------------------------------- /Section 11/Exercice 4/02-solution/la_concatenation.py: -------------------------------------------------------------------------------- 1 | a = "J'ai une classe de " + str(30) + " élèves" 2 | b = str(10) + " + " + "5" + " est égal à " + str(15) 3 | c = 10 + int("5") 4 | d = "L'addition de 10 + 5 est égal à " + str(10 + 5) -------------------------------------------------------------------------------- /Section 14/Exercice 5/01-sources/devine_un_nombre_01.py: -------------------------------------------------------------------------------- 1 | nombre_mystere = 7 2 | 3 | # Demander à l'utilisateur de deviner le nombre. 4 | # Afficher si le nombre entré par l'utilisateur est égal au nombre mystère. -------------------------------------------------------------------------------- /Section 14/Exercice 5/02-solution/devine_un_nombre_01.py: -------------------------------------------------------------------------------- 1 | nombre_mystere = 7 2 | 3 | nombre_utilisateur = input("Quel est le nombre mystère ? ") 4 | 5 | resultat = int(nombre_utilisateur) == nombre_mystere 6 | print(resultat) -------------------------------------------------------------------------------- /Section 15/Session 64/script.py: -------------------------------------------------------------------------------- 1 | age = 20 2 | if age >= 18: 3 | print("Vous êtes majeur !") -------------------------------------------------------------------------------- /Section 15/Session 65/script.py: -------------------------------------------------------------------------------- 1 | age = 20 2 | langage == "Python" 3 | 4 | if age >= 18: 5 | print("Vous êtes majeur !") 6 | if langage == "Python": 7 | print("Vous pouvez rentrer") 8 | 9 | print("Le script est terminé") -------------------------------------------------------------------------------- /Section 15/Session 66/script.py: -------------------------------------------------------------------------------- 1 | age = 15 2 | if age >= 18: 3 | print("Vous êtes majeur") 4 | elif age < 18: 5 | print("Vous êtes mineur") -------------------------------------------------------------------------------- /Section 15/Session 67/script.py: -------------------------------------------------------------------------------- 1 | utilisateur = "root" 2 | if utilisateur == "admin": 3 | print("Accès autorisé !") 4 | elif utilisateur == "root": 5 | print("Accès autorisé !") 6 | else: 7 | print("Accès refusé...") -------------------------------------------------------------------------------- /Section 17/Exercice 7/01-sources/devine_un_nombre_02.py: -------------------------------------------------------------------------------- 1 | nombre_mystere = 7 2 | 3 | nombre_utilisateur = input("Quel est le nombre mystère ? ") 4 | 5 | resultat = int(nombre_utilisateur) == nombre_mystere 6 | print(resultat) 7 | 8 | # Afficher si le nombre entré par l'utilisateur est plus grand, plus petit ou égal au nombre mystère. 9 | -------------------------------------------------------------------------------- /Section 17/Exercice 7/02-solution/devine_un_nombre_02.py: -------------------------------------------------------------------------------- 1 | nombre_mystere = 7 2 | nombre = input("Quel est le nombre mystère ? ") 3 | 4 | nombre = int(nombre) 5 | if nombre > nombre_mystere: 6 | print(f"Le nombre mystère est plus petit que {nombre}") 7 | elif nombre < nombre_mystere: 8 | print(f"Le nombre mystère est plus grand que {nombre}") 9 | else: 10 | print("Bravo, vous avez trouvé le nombre mystère !") 11 | -------------------------------------------------------------------------------- /Section 18/Session 76/script.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | r = random.randint(0, 1) 4 | r = random.uniform(0, 1) 5 | r = random.randrange(2) 6 | r = random.randrange(0, 101, 10) -------------------------------------------------------------------------------- /Section 18/Session 77/script.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | chemin = "/Users/thibh/formation-developpeur-python" 4 | dossier = os.path.join(chemin, "dossier", "test") 5 | if os.path.exists(dossier): 6 | os.removedirs(dossier) -------------------------------------------------------------------------------- /Section 18/Session 78/script.py: -------------------------------------------------------------------------------- 1 | import random 2 | from pprint import pprint 3 | print(dir(random)) -------------------------------------------------------------------------------- /Section 19/Exercice 8/01-sources/devine_un_nombre_03.py: -------------------------------------------------------------------------------- 1 | # Remplacer le nombre mystère par un nombre aléatoire 2 | nombre_mystere = 7 3 | 4 | nombre_utilisateur = input("Quel est le nombre mystère ? ") 5 | 6 | resultat = int(nombre_utilisateur) == nombre_mystere 7 | print(resultat) -------------------------------------------------------------------------------- /Section 19/Exercice 8/02-solution/devine_un_nombre_03.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | nombre_mystere = random.randint(0, 10) 4 | nombre_utilisateur = input("Quel est le nombre mystère ? ") 5 | 6 | resultat = int(nombre_utilisateur) == nombre_mystere 7 | 8 | print(resultat) 9 | -------------------------------------------------------------------------------- /Section 20/Session 80/script.py: -------------------------------------------------------------------------------- 1 | liste = [250, "Python", True] -------------------------------------------------------------------------------- /Section 20/Session 82/script.py: -------------------------------------------------------------------------------- 1 | liste = [5] 2 | liste.append(3) # [5, 3] 3 | liste.extend([20, "Python"]) # [5, 3, 20, "Python"] 4 | liste.remove("Python") # [5, 3, 20] -------------------------------------------------------------------------------- /Section 20/Session 83/script.py: -------------------------------------------------------------------------------- 1 | liste = ["Python", "C++", "Java"] 2 | liste[0] # "Python" 3 | liste[1] # "C++" 4 | liste[2] # "Java" 5 | liste[-1] # "Java" 6 | liste[-2] # "C++" 7 | liste[-3] # "Python" 8 | liste[-4] # Erreur ! Indice hors des limites de la liste 9 | liste[3] # Erreur ! Indice hors des limites de la liste -------------------------------------------------------------------------------- /Section 20/Session 85/script.py: -------------------------------------------------------------------------------- 1 | liste = ["Utilisateur_01", 2 | "Utilisateur_02", 3 | "Utilisateur_03", 4 | "Utilisateur_04", 5 | "Utilisateur_05", 6 | "Utilisateur_06"] 7 | 8 | liste[:] # ['Utilisateur_01', 'Utilisateur_02', 'Utilisateur_03', 'Utilisateur_04', 'Utilisateur_05', 'Utilisateur_06'] 9 | liste[1:] # ['Utilisateur_02', 'Utilisateur_03', 'Utilisateur_04', 'Utilisateur_05', 'Utilisateur_06'] 10 | liste[:1] # ['Utilisateur_01'] 11 | liste[1:3] # ['Utilisateur_02', 'Utilisateur_03'] 12 | liste[1:-1] # ['Utilisateur_02', 'Utilisateur_03', 'Utilisateur_04', 'Utilisateur_05'] -------------------------------------------------------------------------------- /Section 20/Session 87/script.py: -------------------------------------------------------------------------------- 1 | employes = ["Carlos", "Max", "Martine", "Patrick", "Alex", "Max"] 2 | employes.index("Alex") # 4 3 | employes.count("Max") # 2 4 | employes.sort() # Trie la liste en la modifiant directement : ["Alex", "Carlos", "Martine", "Max", "Max", "Patrick"] 5 | sorted(employes) # Trie la liste mais ne modifie pas la liste d'origine ! 6 | liste_trie = sorted(employes) # On retourne la liste triée dans une nouvelle liste. 7 | 8 | nombres = [10, 1, 5, 15] 9 | nombres.reverse() # Inverse l'ordre de la liste : [15, 5, 1, 10] 10 | print(nombres) -------------------------------------------------------------------------------- /Section 20/Session 88/script.py: -------------------------------------------------------------------------------- 1 | employes = ["Carlos", "Max", "Martine", "Patrick", "Alex"] 2 | element = employes.pop(-1) # retire le dernier élément de la liste (ici, "Alex") et le retourne dans la variable 'element' 3 | print(element) # affiche 'Alex' 4 | employes.clear() # supprime tous les éléments de la liste -------------------------------------------------------------------------------- /Section 20/Session 89/script.py: -------------------------------------------------------------------------------- 1 | liste = ["Python", "est", "un", "langage", "incroyable"] 2 | " ".join(liste) # 'Python est un langage incroyable' 3 | " - ".join(liste) # Python - est - un - langage - incroyable 4 | "".join(liste) # Pythonestunlangageincroyable 5 | 6 | resultat = "\n".join(liste) 7 | print(resultat) 8 | # Python 9 | # est 10 | # un 11 | # langage 12 | # incroyable -------------------------------------------------------------------------------- /Section 20/Session 90/script.py: -------------------------------------------------------------------------------- 1 | utilisateurs = ["Paul", "Pierre", "Marie"] 2 | "Paul" in utilisateurs # retourne le booléen True 3 | 4 | if "Paul" in utilisateurs: 5 | print("Bonjour Paul, bon retour parmi nous!") 6 | 7 | if "Paul" in utilisateurs: 8 | utilisateurs.remove("Paul") 9 | 10 | # Fonction aussi avec des chaînes de caractères 11 | "Java" in "Javascript" # retourne le booléen True -------------------------------------------------------------------------------- /Section 20/Session 91/script.py: -------------------------------------------------------------------------------- 1 | liste = ["Python", ["Java", "C++", ["C"]], ["Ruby"]] 2 | 3 | liste[0] # 'Python' 4 | liste[-1][0] # 'Ruby' 5 | liste[0][0:2] # 'Py' 6 | liste[1][1] # 'C++' 7 | liste[1][:2] # ['Java', 'C++'] -------------------------------------------------------------------------------- /Section 21/Exercice 9/solution/script.py: -------------------------------------------------------------------------------- 1 | mdp = input("Entrez un mot de passe (min 8 caractères) : ") 2 | mdp_trop_court = "votre mot de passe est trop court." 3 | 4 | if len(mdp) == 0: 5 | print(mdp_trop_court.upper()) 6 | exit() 7 | elif len(mdp) < 8: 8 | print(mdp_trop_court.capitalize()) 9 | exit() 10 | 11 | if mdp.isdigit(): 12 | print("Votre mot de passe ne contient que des nombres.") 13 | exit() 14 | 15 | print("Inscription terminée.") 16 | -------------------------------------------------------------------------------- /Section 21/Exercice 9/sources/script.py: -------------------------------------------------------------------------------- 1 | mdp = input("Entrez un mot de passe (min 8 caractères) : ") 2 | mdp_trop_court = "votre mot de passe est trop court." -------------------------------------------------------------------------------- /Section 22/Exercice 10/01-sources/devine_un_nombre_04.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | nombre_mystere = random.randint(0, 10) 4 | nombre = input("Quel est le nombre mystère ? ") 5 | nombre = int(nombre) 6 | 7 | if nombre > nombre_mystere: 8 | print(f"Le nombre mystère est plus petit que {nombre}") 9 | elif nombre < nombre_mystere: 10 | print(f"Le nombre mystère est plus grand que {nombre}") 11 | else: 12 | print("Bravo, vous avez trouvé le nombre mystère !") 13 | -------------------------------------------------------------------------------- /Section 22/Exercice 10/02-solution/devine_un_nombre_04.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | nombre_mystere = random.randint(0, 10) 4 | nombre = input("Quel est le nombre mystère ? ") 5 | if not nombre.isdigit(): 6 | print("SVP, entrez un nombre valide.") 7 | exit() 8 | 9 | nombre = int(nombre) 10 | if nombre > nombre_mystere: 11 | print(f"Le nombre mystère est plus petit que {nombre}") 12 | elif nombre < nombre_mystere: 13 | print(f"Le nombre mystère est plus grand que {nombre}") 14 | else: 15 | print("Bravo, vous avez trouvé le nombre mystère !") 16 | -------------------------------------------------------------------------------- /Section 23/Exercice 11/01-sources/comprehension_de_liste.py: -------------------------------------------------------------------------------- 1 | nombres = [1, 21, 5, 44, 4, 9, 5, 83, 29, 31, 25, 38] 2 | nombres_pairs = [] 3 | for i in nombres: 4 | if i % 2 == 0: 5 | nombres_pairs.append(i) 6 | 7 | print(nombres_pairs) 8 | 9 | # ---------------------------------------------------- # 10 | 11 | nombres = range(-10, 10) 12 | nombres_positifs = [] 13 | for i in nombres: 14 | if i >= 0: 15 | nombres_positifs.append(i) 16 | 17 | print(nombres_positifs) 18 | 19 | # ---------------------------------------------------- # 20 | 21 | nombres = range(5) 22 | nombres_doubles = [] 23 | for i in nombres: 24 | nombres_doubles.append(i * 2) 25 | 26 | print(nombres_doubles) 27 | 28 | # ---------------------------------------------------- # 29 | 30 | nombres = range(10) 31 | nombres_inverses = [] 32 | for i in nombres: 33 | if i % 2 == 0: 34 | nombres_inverses.append(i) 35 | else: 36 | nombres_inverses.append(-i) 37 | 38 | print(nombres_inverses) -------------------------------------------------------------------------------- /Section 23/Exercice 11/02-solutions/comprehension_de_liste.py.py: -------------------------------------------------------------------------------- 1 | nombres = [1, 21, 5, 44, 4, 9, 5, 83, 29, 31, 25, 38] 2 | nombres_pairs = [i for i in nombres if i % 2 == 0] 3 | print(nombres_pairs) 4 | 5 | # ---------------------------------------------------- # 6 | 7 | nombres = range(-10, 10) 8 | nombres_positifs = [i for i in nombres if i >= 0] 9 | print(nombres_positifs) 10 | 11 | # ---------------------------------------------------- # 12 | 13 | nombres = range(5) 14 | nombres_doubles = [i * 2 for i in nombres] 15 | print(nombres_doubles) 16 | 17 | # ---------------------------------------------------- # 18 | 19 | nombres = range(10) 20 | nombres_inverses = [i if i % 2 == 0 else -i for i in nombres] 21 | print(nombres_inverses) -------------------------------------------------------------------------------- /Section 24/Exercice 12/01-sources/afficher_utilisateurs.py: -------------------------------------------------------------------------------- 1 | """ 2 | Votre script doit afficher les chaînes de caractères suivantes : 3 | 4 | Utilisateur 1 5 | Utilisateur 2 6 | Utilisateur 3 7 | Utilisateur 4 8 | Utilisateur 5 9 | Utilisateur 6 10 | Utilisateur 7 11 | Utilisateur 8 12 | Utilisateur 9 13 | Utilisateur 10 14 | """ 15 | -------------------------------------------------------------------------------- /Section 24/Exercice 12/02-solution/afficher_utilisateurs.py: -------------------------------------------------------------------------------- 1 | # Solution #1 2 | for i in range(10): 3 | print(f"Utilisateur {i + 1}") 4 | 5 | # Solution #2 6 | for i in range(1, 11): 7 | print(f"Utilisateur {i}") -------------------------------------------------------------------------------- /Section 24/Exercice 13/01-sources/afficher_un_mot_a_lenvers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Dans cet exercice vous devez afficher les lettres du mot 'Python' dans le sens inverse. 3 | Votre script devra donc afficher : 4 | n 5 | o 6 | h 7 | t 8 | y 9 | P 10 | """ -------------------------------------------------------------------------------- /Section 24/Exercice 13/02-solution/afficher_un_mot_a_lenvers.py: -------------------------------------------------------------------------------- 1 | # Solution 1 2 | mot = "Python" 3 | for lettre in reversed(mot): 4 | print(lettre) 5 | 6 | # Solution 2 7 | mot = "Python" 8 | for lettre in mot[::-1]: 9 | print(lettre) -------------------------------------------------------------------------------- /Section 24/Exercice 14/01-sources/sortir_boucle_while.py: -------------------------------------------------------------------------------- 1 | # Comment peut-on permettre à l'utilisateur de sortir de la boucle 2 | # en modifiant les lignes de code dans la boucle while ? 3 | 4 | continuer = "o" 5 | while continuer == "o": 6 | print("On continue !") 7 | input("Voulez-vous continuer ? o/n ") -------------------------------------------------------------------------------- /Section 24/Exercice 14/02-solution/sortir_boucle_while.py: -------------------------------------------------------------------------------- 1 | # Solution 1 2 | continuer = "o" 3 | while continuer == "o": 4 | print("On continue !") 5 | continuer = input("Voulez-vous continuer ? o/n ") 6 | 7 | # Solution 2 8 | continuer = "o" 9 | while continuer == "o": 10 | print("On continue !") 11 | resultat = input("Voulez-vous continuer ? o/n ") 12 | if resultat != "o": 13 | break 14 | 15 | # Solution 3 avec Python 3.8 uniquement 16 | while (continuer := "o") == "o": 17 | print("On continue !") 18 | if (resultat := input("Voulez-vous continuer ? o/n ")) != "o": 19 | break -------------------------------------------------------------------------------- /Section 25/Exercice 15/01-sources/devine_un_nombre_05.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | nombre_mystere = random.randint(0, 10) 4 | nombre = input("Quel est le nombre mystère ? ") 5 | if not nombre.isdigit(): 6 | print("SVP, entrez un nombre valide.") 7 | exit() 8 | 9 | nombre = int(nombre) 10 | 11 | if nombre > nombre_mystere: 12 | print(f"Le nombre mystère est plus petit que {nombre}") 13 | elif nombre < nombre_mystere: 14 | print(f"Le nombre mystère est plus grand que {nombre}") 15 | else: 16 | print("Bravo, vous avez trouvé le nombre mystère !") 17 | 18 | -------------------------------------------------------------------------------- /Section 25/Exercice 15/02-solution/devine_un_nombre_05.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | nombre_mystere = random.randint(0, 50) 4 | nombre_essais = 5 5 | essais = 0 6 | 7 | while essais < nombre_essais: 8 | nombre = input("Quel est le nombre mystère ? ") 9 | 10 | if not nombre.isdigit(): 11 | print("SVP, entrez un nombre valide.") 12 | continue 13 | 14 | nombre = int(nombre) 15 | 16 | if nombre > nombre_mystere: 17 | print(f"Le nombre mystère est plus petit que {nombre}") 18 | elif nombre < nombre_mystere: 19 | print(f"Le nombre mystère est plus grand que {nombre}") 20 | else: 21 | print("Bravo, vous avez trouvé le nombre mystère !") 22 | exit() 23 | 24 | essais += 1 25 | 26 | print(f"Vous avez perdu. Le nombre mystère était {nombre_mystere}") 27 | -------------------------------------------------------------------------------- /Section 28/Exercice 16/01-sources/la_liste_de_courses_01.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | dossier_courant = os.path.dirname(__file__) -------------------------------------------------------------------------------- /Section 28/Exercice 16/02-solutions/la_liste_de_courses_01.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | -------------------------------------------------------------------------------- /Section 28/Exercice 17/01-sources/la_liste_de_courses_02.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | 13 | affichage = """ 14 | Choisissez une option: 15 | \t1: Ajouter un élément 16 | \t2: Enlever un élément 17 | \t3: Afficher la liste 18 | \t4: Vider la liste 19 | \t5: Terminer 20 | """ -------------------------------------------------------------------------------- /Section 28/Exercice 17/02-solutions/la_liste_de_courses_02.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | 13 | affichage = """ 14 | Choisissez une option: 15 | \t1: Ajouter un élément 16 | \t2: Enlever un élément 17 | \t3: Afficher la liste 18 | \t4: Vider la liste 19 | \t5: Terminer 20 | """ 21 | 22 | option = "0" 23 | 24 | while option != "5": 25 | option = input(affichage) -------------------------------------------------------------------------------- /Section 28/Exercice 18/01-sources/la_liste_de_courses_03.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | 13 | affichage = """ 14 | Choisissez une option: 15 | \t1: Ajouter un élément 16 | \t2: Enlever un élément 17 | \t3: Afficher la liste 18 | \t4: Vider la liste 19 | \t5: Terminer 20 | """ 21 | 22 | option = "0" 23 | 24 | while option != "5": 25 | option = input(affichage) -------------------------------------------------------------------------------- /Section 28/Exercice 18/02-solutions/la_liste_de_courses_03.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | 13 | affichage = """ 14 | Choisissez une option: 15 | \t1: Ajouter un élément 16 | \t2: Enlever un élément 17 | \t3: Afficher la liste 18 | \t4: Vider la liste 19 | \t5: Terminer 20 | """ 21 | 22 | option = "0" 23 | 24 | while option != "5": 25 | option = input(affichage) 26 | if option == "1": 27 | item_a_ajouter = input("Entrez le nom de l'élément à ajouter: ") 28 | liste_de_courses.append(item_a_ajouter) 29 | elif option == "2": 30 | item_a_retirer = input("Entrez le nom de l'élément à enlever: ") 31 | if item_a_retirer in liste_de_courses: 32 | liste_de_courses.remove(item_a_retirer) -------------------------------------------------------------------------------- /Section 28/Exercice 19/01-sources/la_liste_de_courses_04.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | 13 | affichage = """ 14 | Choisissez une option: 15 | \t1: Ajouter un élément 16 | \t2: Enlever un élément 17 | \t3: Afficher la liste 18 | \t4: Vider la liste 19 | \t5: Terminer 20 | """ 21 | 22 | option = "0" 23 | 24 | while option != "5": 25 | option = input(affichage) 26 | if option == "1": 27 | item_a_ajouter = input("Entrez le nom de l'élément à ajouter: ") 28 | liste_de_courses.append(item_a_ajouter) 29 | elif option == "2": 30 | item_a_retirer = input("Entrez le nom de l'élément à enlever: ") 31 | if item_a_retirer in liste_de_courses: 32 | liste_de_courses.remove(item_a_retirer) -------------------------------------------------------------------------------- /Section 28/Exercice 19/02-solutions/la_liste_de_courses_04.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | 13 | affichage = """ 14 | Choisissez une option: 15 | \t1: Ajouter un élément 16 | \t2: Enlever un élément 17 | \t3: Afficher la liste 18 | \t4: Vider la liste 19 | \t5: Terminer 20 | """ 21 | 22 | option = "0" 23 | 24 | while option != "5": 25 | option = input(affichage) 26 | if option == "1": 27 | item_a_ajouter = input("Entrez le nom de l'élément à ajouter: ") 28 | liste_de_courses.append(item_a_ajouter) 29 | elif option == "2": 30 | item_a_retirer = input("Entrez le nom de l'élément à enlever: ") 31 | if item_a_retirer in liste_de_courses: 32 | liste_de_courses.remove(item_a_retirer) 33 | elif option == "3": 34 | if liste_de_courses: 35 | print("\n".join(liste_de_courses)) 36 | else: 37 | print("La liste ne contient aucun élément.") 38 | elif option == "4": 39 | liste_de_courses.clear() -------------------------------------------------------------------------------- /Section 28/Exercice 20/01-sources/la_liste_de_courses_05.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | 13 | affichage = """ 14 | Choisissez une option: 15 | \t1: Ajouter un élément 16 | \t2: Enlever un élément 17 | \t3: Afficher la liste 18 | \t4: Vider la liste 19 | \t5: Terminer 20 | """ 21 | 22 | option = "0" 23 | 24 | while option != "5": 25 | option = input(affichage) 26 | if option == "1": 27 | item_a_ajouter = input("Entrez le nom de l'élément à ajouter: ") 28 | liste_de_courses.append(item_a_ajouter) 29 | elif option == "2": 30 | item_a_retirer = input("Entrez le nom de l'élément à enlever: ") 31 | if item_a_retirer in liste_de_courses: 32 | liste_de_courses.remove(item_a_retirer) 33 | elif option == "3": 34 | if liste_de_courses: 35 | print("\n".join(liste_de_courses)) 36 | else: 37 | print("La liste ne contient aucun élément.") 38 | elif option == "4": 39 | liste_de_courses.clear() -------------------------------------------------------------------------------- /Section 28/Exercice 20/02-solutions/la_liste_de_courses_05.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | dossier_courant = os.path.dirname(__file__) 5 | chemin_liste = os.path.join(dossier_courant, "liste.json") 6 | 7 | if os.path.exists(chemin_liste): 8 | with open(chemin_liste, "r") as f: 9 | liste_de_courses = json.load(f) 10 | else: 11 | liste_de_courses = [] 12 | 13 | affichage = """ 14 | Choisissez une option: 15 | \t1: Ajouter un élément 16 | \t2: Enlever un élément 17 | \t3: Afficher la liste 18 | \t4: Vider la liste 19 | \t5: Terminer 20 | """ 21 | 22 | option = "0" 23 | 24 | while option != "5": 25 | option = input(affichage) 26 | if option == "1": 27 | item_a_ajouter = input("Entrez le nom de l'élément à ajouter: ") 28 | liste_de_courses.append(item_a_ajouter) 29 | elif option == "2": 30 | item_a_retirer = input("Entrez le nom de l'élément à enlever: ") 31 | if item_a_retirer in liste_de_courses: 32 | liste_de_courses.remove(item_a_retirer) 33 | elif option == "3": 34 | if liste_de_courses: 35 | print("\n".join(liste_de_courses)) 36 | else: 37 | print("La liste ne contient aucun élément.") 38 | elif option == "4": 39 | liste_de_courses.clear() 40 | 41 | with open(chemin_liste, "w") as f: 42 | json.dump(liste_de_courses, f, indent=4) 43 | -------------------------------------------------------------------------------- /Section 30/Exercice 21/01-sources/structure_dossier.py: -------------------------------------------------------------------------------- 1 | chemin = "/Users/thibh/dossier_test" 2 | 3 | d = {"Films": ["Le seigneur des anneaux", 4 | "Harry Potter", 5 | "Moon", 6 | "Forrest Gump"], 7 | "Employes": ["Paul", 8 | "Pierre", 9 | "Marie"], 10 | "Exercices": ["les_variables", 11 | "les_fichiers", 12 | "les_boucles"]} 13 | -------------------------------------------------------------------------------- /Section 30/Exercice 21/02-solution/structure_dossier.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | chemin = "/Users/thibh/dossier_test" 4 | 5 | d = {"Films": ["Le seigneur des anneaux", 6 | "Harry Potter", 7 | "Moon", 8 | "Forrest Gump"], 9 | "Employes": ["Paul", 10 | "Pierre", 11 | "Marie"], 12 | "Exercices": ["les_variables", 13 | "les_fichiers", 14 | "les_boucles"]} 15 | 16 | for key, value in d.items(): 17 | for dossier in value: 18 | chemin_dossier = os.path.join(chemin, key, dossier) 19 | os.makedirs(chemin_dossier, exist_ok=True) -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/chercher_un_mot.py: -------------------------------------------------------------------------------- 1 | import glob 2 | 3 | dossier = "/Users/thibh/formation-developpeur-python/exercices/systeme_exploitation/chercher_un_mot/sources/dossier_exemple/**" 4 | files = glob.glob(dossier, recursive=True) 5 | -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/administratif/adresses.json: -------------------------------------------------------------------------------- 1 | {"Paul": {"adresse": "4 Rue de la Paix", "ville": "Paris"}, 2 | "Marie": {"adresse": "5 Chemin de Traverse", "ville": "Londres"}, 3 | "Julien": {"adresse": "10 Boulevard Montparnasse", "ville": "Marseille"}} -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/administratif/comptes_bancaires.json: -------------------------------------------------------------------------------- 1 | { 2 | "Credit Mutuel": { 3 | "Numero de compte": 92817 4 | }, 5 | "Boursorama": { 6 | "Numero de compte": 32928 7 | }, 8 | "Societe Generale": { 9 | "Numero de compte": 19734 10 | } 11 | } -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/administratif/securite_sociale.txt: -------------------------------------------------------------------------------- 1 | Numéro de sécurité sociale:123456789 -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chat_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chat_01.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chat_02.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chat_02.jpeg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chat_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chat_03.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chat_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chat_04.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_01.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_01.jpeg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_02.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_03.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_04.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/01-sources/dossier_exemple/images/chien_05.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/01-sources/dossier_exemple/notes/notes_diverses.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet consectetur adipisicing elit. 2 | Incidunt exercitationem suscipit cupiditate voluptatem praesentium a 3 | adipisci repudiandae quis beatae doloribus in placeat, 4 | pariatur tenetur libero aliquam repellendus doloremque! Maxime, sit. -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/chercher_un_mot.py: -------------------------------------------------------------------------------- 1 | import json 2 | import glob 3 | 4 | dossier = "/Users/thibh/formation-developpeur-python/exercices/systeme_exploitation/chercher_un_mot/sources/dossier_exemple/**" 5 | files = glob.glob(dossier, recursive=True) 6 | 7 | numero_de_compte = None 8 | numero_securite_sociale = None 9 | 10 | for f in files: 11 | if f.endswith(".json"): 12 | with open(f, "r") as f: 13 | contenu = json.load(f) 14 | if "Credit Mutuel" in contenu: 15 | numero_de_compte = contenu["Credit Mutuel"]["Numero de compte"] 16 | elif f.endswith(".txt"): 17 | with open(f, "r") as f: 18 | contenu = f.read() 19 | if "Numéro de sécurité sociale" in contenu: 20 | numero_securite_sociale = contenu.split(":")[-1] 21 | 22 | print(numero_de_compte) 23 | print(numero_securite_sociale) -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/administratif/adresses.json: -------------------------------------------------------------------------------- 1 | {"Paul": {"adresse": "4 Rue de la Paix", "ville": "Paris"}, 2 | "Marie": {"adresse": "5 Chemin de Traverse", "ville": "Londres"}, 3 | "Julien": {"adresse": "10 Boulevard Montparnasse", "ville": "Marseille"}} -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/administratif/comptes_bancaires.json: -------------------------------------------------------------------------------- 1 | { 2 | "Credit Mutuel": { 3 | "Numero de compte": 92817 4 | }, 5 | "Boursorama": { 6 | "Numero de compte": 32928 7 | }, 8 | "Societe Generale": { 9 | "Numero de compte": 19734 10 | } 11 | } -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/administratif/securite_sociale.txt: -------------------------------------------------------------------------------- 1 | Numéro de sécurité sociale:123456789 -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chat_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chat_01.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chat_02.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chat_02.jpeg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chat_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chat_03.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chat_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chat_04.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_01.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_01.jpeg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_02.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_03.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_04.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 22/02-solution/dossier_exemple/images/chien_05.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 22/02-solution/dossier_exemple/notes/notes_diverses.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet consectetur adipisicing elit. 2 | Incidunt exercitationem suscipit cupiditate voluptatem praesentium a 3 | adipisci repudiandae quis beatae doloribus in placeat, 4 | pariatur tenetur libero aliquam repellendus doloremque! Maxime, sit. -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/chercher_un_mot.py: -------------------------------------------------------------------------------- 1 | import glob 2 | 3 | dossier = "/Users/thibh/formation-developpeur-python/exercices/systeme_exploitation/chercher_un_mot/sources/dossier_exemple/**" 4 | files = glob.glob(dossier, recursive=True) 5 | -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/administratif/adresses.json: -------------------------------------------------------------------------------- 1 | {"Paul": {"adresse": "4 Rue de la Paix", "ville": "Paris"}, 2 | "Marie": {"adresse": "5 Chemin de Traverse", "ville": "Londres"}, 3 | "Julien": {"adresse": "10 Boulevard Montparnasse", "ville": "Marseille"}} -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/administratif/comptes_bancaires.json: -------------------------------------------------------------------------------- 1 | { 2 | "Credit Mutuel": { 3 | "Numero de compte": 92817 4 | }, 5 | "Boursorama": { 6 | "Numero de compte": 32928 7 | }, 8 | "Societe Generale": { 9 | "Numero de compte": 19734 10 | } 11 | } -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/administratif/securite_sociale.txt: -------------------------------------------------------------------------------- 1 | Numéro de sécurité sociale:123456789 -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chat_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chat_01.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chat_02.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chat_02.jpeg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chat_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chat_03.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chat_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chat_04.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_01.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_01.jpeg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_02.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_03.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_04.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/01-sources/dossier_exemple/images/chien_05.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/01-sources/dossier_exemple/notes/notes_diverses.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet consectetur adipisicing elit. 2 | Incidunt exercitationem suscipit cupiditate voluptatem praesentium a 3 | adipisci repudiandae quis beatae doloribus in placeat, 4 | pariatur tenetur libero aliquam repellendus doloremque! Maxime, sit. -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/chercher_un_mot.py: -------------------------------------------------------------------------------- 1 | import json 2 | import glob 3 | 4 | dossier = "/Users/thibh/formation-developpeur-python/exercices/systeme_exploitation/chercher_un_mot/sources/dossier_exemple/**" 5 | files = glob.glob(dossier, recursive=True) 6 | 7 | numero_de_compte = None 8 | numero_securite_sociale = None 9 | 10 | for f in files: 11 | if f.endswith(".json"): 12 | with open(f, "r") as f: 13 | contenu = json.load(f) 14 | if "Credit Mutuel" in contenu: 15 | numero_de_compte = contenu["Credit Mutuel"]["Numero de compte"] 16 | elif f.endswith(".txt"): 17 | with open(f, "r") as f: 18 | contenu = f.read() 19 | if "Numéro de sécurité sociale" in contenu: 20 | numero_securite_sociale = contenu.split(":")[-1] 21 | 22 | print(numero_de_compte) 23 | print(numero_securite_sociale) -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/administratif/adresses.json: -------------------------------------------------------------------------------- 1 | {"Paul": {"adresse": "4 Rue de la Paix", "ville": "Paris"}, 2 | "Marie": {"adresse": "5 Chemin de Traverse", "ville": "Londres"}, 3 | "Julien": {"adresse": "10 Boulevard Montparnasse", "ville": "Marseille"}} -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/administratif/comptes_bancaires.json: -------------------------------------------------------------------------------- 1 | { 2 | "Credit Mutuel": { 3 | "Numero de compte": 92817 4 | }, 5 | "Boursorama": { 6 | "Numero de compte": 32928 7 | }, 8 | "Societe Generale": { 9 | "Numero de compte": 19734 10 | } 11 | } -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/administratif/securite_sociale.txt: -------------------------------------------------------------------------------- 1 | Numéro de sécurité sociale:123456789 -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chat_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chat_01.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chat_02.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chat_02.jpeg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chat_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chat_03.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chat_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chat_04.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_01.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_01.jpeg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_02.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_03.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_04.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 30/Exercice 23/02-solution/dossier_exemple/images/chien_05.jpg -------------------------------------------------------------------------------- /Section 30/Exercice 23/02-solution/dossier_exemple/notes/notes_diverses.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet consectetur adipisicing elit. 2 | Incidunt exercitationem suscipit cupiditate voluptatem praesentium a 3 | adipisci repudiandae quis beatae doloribus in placeat, 4 | pariatur tenetur libero aliquam repellendus doloremque! Maxime, sit. -------------------------------------------------------------------------------- /Section 31/Exercice 24/01-sources/fichier_invalide.abc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 31/Exercice 24/01-sources/fichier_invalide.abc -------------------------------------------------------------------------------- /Section 31/Exercice 24/01-sources/readme.txt: -------------------------------------------------------------------------------- 1 | J'adore Python ! -------------------------------------------------------------------------------- /Section 31/Exercice 24/02-solution/fichier_invalide.abc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 31/Exercice 24/02-solution/fichier_invalide.abc -------------------------------------------------------------------------------- /Section 31/Exercice 24/02-solution/gerer_erreurs.py: -------------------------------------------------------------------------------- 1 | fichier = input("Entrez un fichier à ouvrir : ") 2 | 3 | try: 4 | f = open(fichier, "r") 5 | print(f.read()) 6 | except FileNotFoundError: 7 | print("Le fichier est introuvable.") 8 | except UnicodeDecodeError: 9 | print("Impossible d'ouvrir le fichier.") 10 | else: 11 | f.close() -------------------------------------------------------------------------------- /Section 31/Exercice 24/02-solution/readme.txt: -------------------------------------------------------------------------------- 1 | J'adore Python ! -------------------------------------------------------------------------------- /Section 33/Session 127/random.py: -------------------------------------------------------------------------------- 1 | a = 5 -------------------------------------------------------------------------------- /Section 33/Session 127/script.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | print(random.a) -------------------------------------------------------------------------------- /Section 33/Session 128/script.py: -------------------------------------------------------------------------------- 1 | import utils 2 | 3 | -------------------------------------------------------------------------------- /Section 33/Session 128/utils.py: -------------------------------------------------------------------------------- 1 | def addition(a, b): 2 | return a + b 3 | 4 | if __name__ == "__main__": 5 | print(addition(4, 5)) -------------------------------------------------------------------------------- /Section 33/Session 129/script.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append("/Users/thibh/Documents/mes_modules") 3 | 4 | import module_test -------------------------------------------------------------------------------- /Section 33/Session 133/script.py: -------------------------------------------------------------------------------- 1 | import utils 2 | import importlib 3 | importlib.reload(utils) 4 | 5 | print(utils.a) -------------------------------------------------------------------------------- /Section 33/Session 133/utils.py: -------------------------------------------------------------------------------- 1 | a = 4 -------------------------------------------------------------------------------- /Section 36/Session 139/script.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | logging.debug("La fonction a bien été exécutée") 4 | logging.info("Message d'information général") 5 | logging.warning("Attention !") 6 | logging.error("Une erreur est arrivée") 7 | logging.critical("Erreur critique") -------------------------------------------------------------------------------- /Section 36/Session 140/script.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | logging.basicConfig(level=logging.ERROR, 4 | format='%(asctime)s : %(levelname)s : %(message)s') 5 | 6 | logging.debug("La fonction a bien été exécutée") 7 | logging.info("Message d'information général") 8 | logging.warning("Attention !") 9 | logging.error("Une erreur est arrivée") 10 | logging.critical("Erreur critique") -------------------------------------------------------------------------------- /Section 36/Session 141/script.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | logging.basicConfig(level=logging.DEBUG, 4 | filename="app.log", 5 | filemode="w", 6 | format='%(asctime)s - %(levelname)s - %(message)s') 7 | 8 | logging.debug("La fonction a bien été exécutée") 9 | logging.info("Message d'information général") 10 | logging.warning("Attention !") 11 | logging.error("Une erreur est arrivée") 12 | logging.critical("Erreur critique") -------------------------------------------------------------------------------- /Section 39/Session 156/classe.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | marque = "Lamborghini" 3 | couleur = "rouge" 4 | 5 | print(Voiture.marque) 6 | print(Voiture.couleur) -------------------------------------------------------------------------------- /Section 39/Session 157/instances.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | marque = "Lamborghini" 3 | 4 | voiture_01 = Voiture() 5 | voiture_02 = Voiture() 6 | print(voiture_01.marque) 7 | print(voiture_02.marque) 8 | -------------------------------------------------------------------------------- /Section 39/Session 158/attributs.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | marque = "Lamborghini" 3 | 4 | voiture_01 = Voiture() 5 | voiture_02 = Voiture() 6 | 7 | # print(voiture_01.marque) 8 | # print(voiture_02.marque) 9 | 10 | Voiture.marque = "Porsche" 11 | 12 | # print(voiture_01.marque) 13 | # print(voiture_02.marque) 14 | 15 | voiture_01.marque = "Peugeolt" 16 | voiture_02.marque = "Volkswagen" 17 | 18 | print(Voiture.marque) 19 | print(voiture_01.marque) 20 | print(voiture_02.marque) -------------------------------------------------------------------------------- /Section 39/Session 159/initialisation.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | voitures_crees = 0 3 | def __init__(self, marque): 4 | Voiture.voitures_crees += 1 5 | self.marque = marque 6 | 7 | voiture_01 = Voiture("Lamborghini") 8 | voiture_02 = Voiture("Porsche") 9 | print(Voiture.voitures_crees) 10 | -------------------------------------------------------------------------------- /Section 39/Session 161/self.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | def __init__(self, marque): 3 | self.marque = marque 4 | 5 | def afficher_marque(self): 6 | print(f"La voiture est une {self.marque}") 7 | 8 | voiture_01 = Voiture("Lamborghini") 9 | voiture_01.afficher_marque() 10 | Voiture.afficher_marque(voiture_01) 11 | -------------------------------------------------------------------------------- /Section 39/Session 163/script.py: -------------------------------------------------------------------------------- 1 | # class str: 2 | # pass 3 | 4 | # a = 5 5 | # a = str(a) 6 | ma_liste = list("python") 7 | print(ma_liste) 8 | -------------------------------------------------------------------------------- /Section 40/Exercice 25/voiture.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | def __init__(self): 3 | self.essence = 100 4 | 5 | def afficher_reservoir(self): 6 | print(f"La voiture contient {self.essence}L d'essence.") 7 | 8 | def roule(self, km): 9 | if self.essence <= 0: 10 | print("Vous n'avez plus d'essence, faites le plein !") 11 | return 12 | 13 | self.essence -= (km * 5) / 100 14 | 15 | if self.essence < 10: 16 | print("Vous n'avez bientôt plus d'essence !") 17 | 18 | self.afficher_reservoir() 19 | 20 | def faire_le_plein(self): 21 | self.essence = 100 22 | print("Vous pouvez repartir !") 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Section 41/Session 166/constants.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | CUR_DIR = os.path.dirname(os.path.abspath(__file__)) 4 | DATA_DIR = os.path.join(CUR_DIR, "data") -------------------------------------------------------------------------------- /Section 41/Session 167/constants.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | CUR_DIR = os.path.dirname(os.path.abspath(__file__)) 4 | DATA_DIR = os.path.join(CUR_DIR, "data") -------------------------------------------------------------------------------- /Section 41/Session 167/lib.py: -------------------------------------------------------------------------------- 1 | class Liste(list): 2 | def __init__(self, nom): 3 | self.nom = nom 4 | 5 | if __name__ == "__main__": 6 | print("Hello") -------------------------------------------------------------------------------- /Section 41/Session 168/constants.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | CUR_DIR = os.path.dirname(os.path.abspath(__file__)) 4 | DATA_DIR = os.path.join(CUR_DIR, "data") -------------------------------------------------------------------------------- /Section 41/Session 168/lib.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | LOGGER = logging.getLogger() 4 | 5 | 6 | class Liste(list): 7 | def __init__(self, nom): 8 | self.nom = nom 9 | 10 | def ajouter(self, element): 11 | if not isinstance(element, str): 12 | raise ValueError("Vous ne pouvez ajouter que des chaînes de caractères!") 13 | 14 | if element in self: 15 | LOGGER.error(f"{element} est déjà dans la liste.") 16 | return False 17 | 18 | self.append(element) 19 | return True 20 | 21 | def enlever(self, element): 22 | if element in self: 23 | self.remove(element) 24 | return True 25 | return False 26 | 27 | if __name__ == "__main__": 28 | liste = Liste("courses") 29 | liste.ajouter("Pommes") 30 | liste.ajouter("Poires") 31 | print(liste) 32 | -------------------------------------------------------------------------------- /Section 41/Session 169/constants.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | CUR_DIR = os.path.dirname(os.path.abspath(__file__)) 4 | DATA_DIR = os.path.join(CUR_DIR, "data") -------------------------------------------------------------------------------- /Section 41/Session 169/lib.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | LOGGER = logging.getLogger() 4 | 5 | 6 | class Liste(list): 7 | def __init__(self, nom): 8 | self.nom = nom 9 | 10 | def ajouter(self, element): 11 | if not isinstance(element, str): 12 | raise ValueError("Vous ne pouvez ajouter que des chaînes de caractères!") 13 | 14 | if element in self: 15 | LOGGER.error(f"{element} est déjà dans la liste.") 16 | return False 17 | 18 | self.append(element) 19 | return True 20 | 21 | def enlever(self, element): 22 | if element in self: 23 | self.remove(element) 24 | return True 25 | return False 26 | 27 | def afficher(self): 28 | print(f"Ma liste de {self.nom} :") 29 | for element in self: 30 | print(f" - {element}") 31 | 32 | if __name__ == "__main__": 33 | liste = Liste("taches") 34 | liste.ajouter("Pommes") 35 | liste.ajouter("Poires") 36 | liste.afficher() -------------------------------------------------------------------------------- /Section 41/Session 170/constants.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | CUR_DIR = os.path.dirname(os.path.abspath(__file__)) 4 | DATA_DIR = os.path.join(CUR_DIR, "data") -------------------------------------------------------------------------------- /Section 41/Session 170/data/courses.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Pommes", 3 | "Poires" 4 | ] -------------------------------------------------------------------------------- /Section 41/Session 170/lib.py: -------------------------------------------------------------------------------- 1 | import json 2 | import logging 3 | import os 4 | 5 | from constants import DATA_DIR 6 | 7 | LOGGER = logging.getLogger() 8 | 9 | 10 | class Liste(list): 11 | def __init__(self, nom): 12 | self.nom = nom 13 | 14 | def ajouter(self, element): 15 | if not isinstance(element, str): 16 | raise ValueError("Vous ne pouvez ajouter que des chaînes de caractères!") 17 | 18 | if element in self: 19 | LOGGER.error(f"{element} est déjà dans la liste.") 20 | return False 21 | 22 | self.append(element) 23 | return True 24 | 25 | def afficher(self): 26 | print(f"Ma liste de {self.nom} :") 27 | for element in self: 28 | print(f" - {element}") 29 | 30 | def enlever(self, element): 31 | if element in self: 32 | self.remove(element) 33 | return True 34 | return False 35 | 36 | def sauvegarder(self): 37 | chemin = os.path.join(DATA_DIR, f"{self.nom}.json") 38 | if not os.path.exists(DATA_DIR): 39 | os.makedirs(DATA_DIR) 40 | 41 | with open(chemin, "w") as f: 42 | json.dump(self, f, indent=4) 43 | 44 | return True 45 | 46 | if __name__ == "__main__": 47 | liste = Liste("courses") 48 | liste.ajouter("Pommes") 49 | liste.ajouter("Poires") 50 | liste.sauvegarder() 51 | -------------------------------------------------------------------------------- /Section 42/Session 170/polymorphisme.py: -------------------------------------------------------------------------------- 1 | class Vehicule: 2 | def avance(self): 3 | print("Le véhicule démarre") 4 | 5 | class Voiture(Vehicule): 6 | def avance(self): 7 | super().avance() 8 | print("La voiture roule") 9 | 10 | class Avion(Vehicule): 11 | def avance(self): 12 | super().avance() 13 | print("L'avion vol") 14 | 15 | v = Voiture() 16 | a = Avion() 17 | v.avance() 18 | a.avance() 19 | -------------------------------------------------------------------------------- /Section 42/Session 171/class_method.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | def __init__(self, marque, vitesse, prix): 3 | self.marque = marque 4 | self.vitesse = vitesse 5 | self.prix = prix 6 | 7 | @classmethod 8 | def lamborghini(cls): 9 | return cls(marque="Lamborghini", vitesse=250, prix=200000) 10 | 11 | @classmethod 12 | def porsche(cls): 13 | return cls(marque="Porsche", vitesse=200, prix=180000) 14 | 15 | lambo = Voiture.lamborghini() 16 | porsche = Voiture.porsche() 17 | -------------------------------------------------------------------------------- /Section 42/Session 172/static_method.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | voiture_crees = 0 3 | def __init__(self, marque, vitesse, prix): 4 | Voiture.voiture_crees += 1 5 | self.marque = marque 6 | self.vitesse = vitesse 7 | self.prix = prix 8 | 9 | @classmethod 10 | def lamborghini(cls): 11 | return cls(marque="Lamborghini", vitesse=250, prix=200000) 12 | 13 | @classmethod 14 | def porsche(cls): 15 | return cls(marque="Porsche", vitesse=200, prix=180000) 16 | 17 | @staticmethod 18 | def afficher_nombre_voitures(): 19 | print(f"Vous avez {Voiture.voiture_crees} voitures dans votre garage.") 20 | 21 | lambo = Voiture.lamborghini() 22 | porsche = Voiture.porsche() 23 | Voiture.afficher_nombre_voitures() -------------------------------------------------------------------------------- /Section 42/Session 173/method_magic.py: -------------------------------------------------------------------------------- 1 | class Voiture: 2 | def __init__(self, marque, vitesse): 3 | self.marque = marque 4 | self.vitesse = vitesse 5 | 6 | def __str__(self): 7 | return f"Voiture de marque {self.marque} avec vitesse maximale de {self.vitesse}." 8 | 9 | porsche = Voiture("Porsche", 200) 10 | affichage = str(porsche) 11 | print(affichage) -------------------------------------------------------------------------------- /Section 42/Session 174/heritage.py: -------------------------------------------------------------------------------- 1 | projets = ["pr_GameOfThrones", "HarryPotter", "pr_Avengers"] 2 | 3 | class Utilisateur: 4 | def __init__(self, nom, prenom): 5 | self.nom = nom 6 | self.prenom = prenom 7 | 8 | def __str__(self): 9 | return f"Utilisateur {self.nom} {self.prenom}" 10 | 11 | def afficher_projets(self): 12 | for projet in projets: 13 | print(projet) 14 | 15 | class Junior(Utilisateur): 16 | def __init__(self, nom, prenom): 17 | Utilisateur.__init__(self, nom, prenom) 18 | 19 | paul = Junior("Paul", "Durand") 20 | paul.afficher_projets() 21 | 22 | -------------------------------------------------------------------------------- /Section 42/Session 175/super.py: -------------------------------------------------------------------------------- 1 | projets = ["pr_GameOfThrones", "HarryPotter", "pr_Avengers"] 2 | class Utilisateur: 3 | def __init__(self, nom, prenom): 4 | self.nom = nom 5 | self.prenom = prenom 6 | 7 | def __str__(self): 8 | return f"Utilisateur {self.nom} {self.prenom}" 9 | 10 | def afficher_projets(self): 11 | for projet in projets: 12 | print(projet) 13 | 14 | class Junior(Utilisateur): 15 | def __init__(self, nom, prenom): 16 | super().__init__(nom, prenom) 17 | 18 | paul = Junior("Paul", "Durand") 19 | paul.afficher_projets() 20 | 21 | -------------------------------------------------------------------------------- /Section 42/Session 176/surcharge.py: -------------------------------------------------------------------------------- 1 | projets = ["pr_GameOfThrones", "HarryPotter", "pr_Avengers"] 2 | class Utilisateur: 3 | def __init__(self, nom, prenom): 4 | self.nom = nom 5 | self.prenom = prenom 6 | 7 | def __str__(self): 8 | return f"Utilisateur {self.nom} {self.prenom}" 9 | 10 | def afficher_projets(self): 11 | for projet in projets: 12 | print(projet) 13 | 14 | class Junior(Utilisateur): 15 | def __init__(self, nom, prenom): 16 | super().__init__(nom, prenom) 17 | 18 | def afficher_projets(self): 19 | for projet in projets: 20 | if not projet.startswith("pr_"): 21 | print(projet) 22 | 23 | paul = Junior("Paul", "Durand") 24 | paul.afficher_projets() 25 | 26 | -------------------------------------------------------------------------------- /Section 43/Session 179/app.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | fichier = "settings.json" 4 | 5 | with open(fichier, "r") as f: 6 | settings = json.load(f) 7 | 8 | settings["fontSize"] = 15 9 | 10 | with open(fichier, "w") as f: 11 | json.dump(settings, f, indent=4) 12 | -------------------------------------------------------------------------------- /Section 43/Session 179/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "fontSize": 15 3 | } -------------------------------------------------------------------------------- /Section 43/Session 180/app.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | conn = sqlite3.connect("database.db") 4 | conn.close() -------------------------------------------------------------------------------- /Section 43/Session 180/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 43/Session 180/database.db -------------------------------------------------------------------------------- /Section 43/Session 181/app.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | conn = sqlite3.connect("database.db") 4 | c = conn.cursor() 5 | 6 | c.execute(""" 7 | CREATE TABLE IF NOT EXISTS employees( 8 | prenom text, 9 | nom text 10 | ) 11 | """) 12 | conn.commit() 13 | conn.close() -------------------------------------------------------------------------------- /Section 43/Session 181/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 43/Session 181/database.db -------------------------------------------------------------------------------- /Section 43/Session 183/app.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | conn = sqlite3.connect("database.db") 4 | c = conn.cursor() 5 | c.execute(""" 6 | CREATE TABLE IF NOT EXISTS employees 7 | ( 8 | prenom text, 9 | nom text 10 | ) 11 | """) 12 | 13 | d = {"prenom": "Paul", "nom": "Dupond"} 14 | c.execute("INSERT INTO employees VALUES (:prenom, :nom)", d) 15 | 16 | conn.commit() 17 | conn.close() -------------------------------------------------------------------------------- /Section 43/Session 183/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 43/Session 183/database.db -------------------------------------------------------------------------------- /Section 43/Session 184/app.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | conn = sqlite3.connect("database.db") 4 | c = conn.cursor() 5 | c.execute(""" 6 | CREATE TABLE IF NOT EXISTS employees 7 | ( 8 | prenom text, 9 | nom text 10 | ) 11 | """) 12 | 13 | 14 | c.execute("SELECT * FROM employees WHERE") 15 | donnees = c.fetchall() 16 | print(donnees) 17 | premier = c.fetchone() 18 | print(premier) 19 | 20 | 21 | conn.commit() 22 | conn.close() -------------------------------------------------------------------------------- /Section 43/Session 184/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 43/Session 184/database.db -------------------------------------------------------------------------------- /Section 43/Session 185/app.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | conn = sqlite3.connect("database.db") 4 | c = conn.cursor() 5 | c.execute(""" 6 | CREATE TABLE IF NOT EXISTS employees 7 | ( 8 | prenom text, 9 | nom text, 10 | salaire int 11 | ) 12 | """) 13 | 14 | d = {"salaire": 20000, "prenom": "Patrick", "nom": "Dupont"} 15 | 16 | c.execute("""UPDATE employees SET salaire=:salaire 17 | WHERE prenom=:prenom AND nom=:nom""", d) 18 | 19 | conn.commit() 20 | conn.close() -------------------------------------------------------------------------------- /Section 43/Session 185/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 43/Session 185/database.db -------------------------------------------------------------------------------- /Section 43/Session 186/app.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | conn = sqlite3.connect("database.db") 4 | c = conn.cursor() 5 | c.execute(""" 6 | CREATE TABLE IF NOT EXISTS employees 7 | ( 8 | prenom text, 9 | nom text 10 | ) 11 | """) 12 | 13 | c.execute("DELETE FROM employees") 14 | 15 | conn.commit() 16 | conn.close() -------------------------------------------------------------------------------- /Section 43/Session 186/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 43/Session 186/database.db -------------------------------------------------------------------------------- /Section 45/Session 192/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtGui, QtCore 2 | 3 | class App(QtWidgets.QWidget): 4 | def __init__(self): 5 | super().__init__() 6 | self.setWindowTitle("Convertisseur de devises") 7 | 8 | app = QtWidgets.QApplication([]) 9 | win = App() 10 | win.show() 11 | app.exec_() -------------------------------------------------------------------------------- /Section 45/Session 193/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtGui, QtCore 2 | 3 | class App(QtWidgets.QWidget): 4 | def __init__(self): 5 | super().__init__() 6 | self.setWindowTitle("Convertisseur de devises") 7 | self.setup_ui() 8 | 9 | def setup_ui(self): 10 | self.layout = QtWidgets.QHBoxLayout(self) 11 | self.cbb_devisesFrom = QtWidgets.QComboBox() 12 | self.le_montant = QtWidgets.QSpinBox() 13 | self.cbb_devisesTo = QtWidgets.QComboBox() 14 | self.le_montantConverti = QtWidgets.QSpinBox() 15 | self.btn_inverser = QtWidgets.QPushButton("Inverser devises") 16 | 17 | self.layout.addWidget(self.cbb_devisesFrom) 18 | self.layout.addWidget(self.le_montant) 19 | self.layout.addWidget(self.cbb_devisesTo) 20 | self.layout.addWidget(self.le_montantConverti) 21 | self.layout.addWidget(self.btn_inverser) 22 | 23 | app = QtWidgets.QApplication([]) 24 | win = App() 25 | win.show() 26 | app.exec_() -------------------------------------------------------------------------------- /Section 45/Session 194/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtGui, QtCore 2 | import currency_converter 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.c = currency_converter.CurrencyConverter() 8 | self.setWindowTitle("Convertisseur de devises") 9 | self.setup_ui() 10 | self.set_default_values() 11 | 12 | def setup_ui(self): 13 | self.layout = QtWidgets.QHBoxLayout(self) 14 | self.cbb_devisesFrom = QtWidgets.QComboBox() 15 | self.le_montant = QtWidgets.QSpinBox() 16 | self.cbb_devisesTo = QtWidgets.QComboBox() 17 | self.le_montantConverti = QtWidgets.QSpinBox() 18 | self.btn_inverser = QtWidgets.QPushButton("Inverser devises") 19 | 20 | self.layout.addWidget(self.cbb_devisesFrom) 21 | self.layout.addWidget(self.le_montant) 22 | self.layout.addWidget(self.cbb_devisesTo) 23 | self.layout.addWidget(self.le_montantConverti) 24 | self.layout.addWidget(self.btn_inverser) 25 | 26 | def set_default_values(self): 27 | self.cbb_devisesFrom.addItems(sorted(list(self.c.currencies))) 28 | self.cbb_devisesTo.addItems(sorted(list(self.c.currencies))) 29 | self.cbb_devisesFrom.setCurrentText("EUR") 30 | self.cbb_devisesTo.setCurrentText("EUR") 31 | self.le_montant.setValue(100) 32 | self.le_montantConverti.setValue(100) 33 | self.le_montant.setRange(1, 1000000) 34 | self.le_montantConverti.setRange(1, 1000000) 35 | 36 | 37 | app = QtWidgets.QApplication([]) 38 | win = App() 39 | win.show() 40 | app.exec_() -------------------------------------------------------------------------------- /Section 45/Session 195/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtGui, QtCore 2 | import currency_converter 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.c = currency_converter.CurrencyConverter() 8 | self.setWindowTitle("Convertisseur de devises") 9 | self.setup_ui() 10 | self.setup_connections() 11 | self.set_default_values() 12 | 13 | def setup_ui(self): 14 | self.layout = QtWidgets.QHBoxLayout(self) 15 | self.cbb_devisesFrom = QtWidgets.QComboBox() 16 | self.le_montant = QtWidgets.QSpinBox() 17 | self.cbb_devisesTo = QtWidgets.QComboBox() 18 | self.le_montantConverti = QtWidgets.QSpinBox() 19 | self.btn_inverser = QtWidgets.QPushButton("Inverser devises") 20 | 21 | self.layout.addWidget(self.cbb_devisesFrom) 22 | self.layout.addWidget(self.le_montant) 23 | self.layout.addWidget(self.cbb_devisesTo) 24 | self.layout.addWidget(self.le_montantConverti) 25 | self.layout.addWidget(self.btn_inverser) 26 | 27 | def setup_connections(self): 28 | self.cbb_devisesFrom.activated.connect(self.compute) 29 | self.cbb_devisesTo.activated.connect(self.compute) 30 | self.le_montant.valueChanged.connect(self.compute) 31 | self.btn_inverser.clicked.connect(self.inverser_devises) 32 | 33 | def set_default_values(self): 34 | self.cbb_devisesFrom.addItems(sorted(list(self.c.currencies))) 35 | self.cbb_devisesTo.addItems(sorted(list(self.c.currencies))) 36 | self.cbb_devisesFrom.setCurrentText("EUR") 37 | self.cbb_devisesTo.setCurrentText("EUR") 38 | self.le_montant.setValue(100) 39 | self.le_montantConverti.setValue(100) 40 | self.le_montant.setRange(1, 1000000) 41 | self.le_montantConverti.setRange(1, 1000000) 42 | 43 | def compute(self): 44 | print("Compute") 45 | 46 | def inverser_devises(self): 47 | print("Inverser devise") 48 | 49 | app = QtWidgets.QApplication([]) 50 | win = App() 51 | win.show() 52 | app.exec_() -------------------------------------------------------------------------------- /Section 45/Session 196/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtGui, QtCore 2 | import currency_converter 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.c = currency_converter.CurrencyConverter() 8 | self.setWindowTitle("Convertisseur de devises") 9 | self.setup_ui() 10 | self.setup_connections() 11 | self.set_default_values() 12 | 13 | def setup_ui(self): 14 | self.layout = QtWidgets.QHBoxLayout(self) 15 | self.cbb_devisesFrom = QtWidgets.QComboBox() 16 | self.le_montant = QtWidgets.QSpinBox() 17 | self.cbb_devisesTo = QtWidgets.QComboBox() 18 | self.le_montantConverti = QtWidgets.QSpinBox() 19 | self.btn_inverser = QtWidgets.QPushButton("Inverser devises") 20 | 21 | self.layout.addWidget(self.cbb_devisesFrom) 22 | self.layout.addWidget(self.le_montant) 23 | self.layout.addWidget(self.cbb_devisesTo) 24 | self.layout.addWidget(self.le_montantConverti) 25 | self.layout.addWidget(self.btn_inverser) 26 | 27 | def setup_connections(self): 28 | self.cbb_devisesFrom.activated.connect(self.compute) 29 | self.cbb_devisesTo.activated.connect(self.compute) 30 | self.le_montant.valueChanged.connect(self.compute) 31 | self.btn_inverser.clicked.connect(self.inverser_devises) 32 | 33 | def set_default_values(self): 34 | self.cbb_devisesFrom.addItems(sorted(list(self.c.currencies))) 35 | self.cbb_devisesTo.addItems(sorted(list(self.c.currencies))) 36 | self.cbb_devisesFrom.setCurrentText("EUR") 37 | self.cbb_devisesTo.setCurrentText("EUR") 38 | self.le_montant.setValue(100) 39 | self.le_montantConverti.setValue(100) 40 | self.le_montant.setRange(1, 1000000) 41 | self.le_montantConverti.setRange(1, 1000000) 42 | 43 | def compute(self): 44 | montant = self.le_montant.value() 45 | deviseFrom = self.cbb_devisesFrom.currentText() 46 | deviseTo = self.cbb_devisesTo.currentText() 47 | resultat = self.c.convert(montant, deviseFrom, deviseTo) 48 | self.le_montantConverti.setValue(resultat) 49 | 50 | def inverser_devises(self): 51 | devise_from = self.cbb_devisesFrom.currentText() 52 | devise_to = self.cbb_devisesTo.currentText() 53 | 54 | self.cbb_devisesFrom.setCurrentText(devise_to) 55 | self.cbb_devisesTo.setCurrentText(devise_from) 56 | self.compute() 57 | 58 | app = QtWidgets.QApplication([]) 59 | win = App() 60 | win.show() 61 | app.exec_() -------------------------------------------------------------------------------- /Section 45/Session 197/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtGui, QtCore 2 | import currency_converter 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.c = currency_converter.CurrencyConverter() 8 | self.setWindowTitle("Convertisseur de devises") 9 | self.setup_ui() 10 | self.setup_connections() 11 | self.set_default_values() 12 | 13 | def setup_ui(self): 14 | self.layout = QtWidgets.QHBoxLayout(self) 15 | self.cbb_devisesFrom = QtWidgets.QComboBox() 16 | self.le_montant = QtWidgets.QSpinBox() 17 | self.cbb_devisesTo = QtWidgets.QComboBox() 18 | self.le_montantConverti = QtWidgets.QSpinBox() 19 | self.btn_inverser = QtWidgets.QPushButton("Inverser devises") 20 | 21 | self.layout.addWidget(self.cbb_devisesFrom) 22 | self.layout.addWidget(self.le_montant) 23 | self.layout.addWidget(self.cbb_devisesTo) 24 | self.layout.addWidget(self.le_montantConverti) 25 | self.layout.addWidget(self.btn_inverser) 26 | 27 | def setup_connections(self): 28 | self.cbb_devisesFrom.activated.connect(self.compute) 29 | self.cbb_devisesTo.activated.connect(self.compute) 30 | self.le_montant.valueChanged.connect(self.compute) 31 | self.btn_inverser.clicked.connect(self.inverser_devises) 32 | 33 | def set_default_values(self): 34 | self.cbb_devisesFrom.addItems(sorted(list(self.c.currencies))) 35 | self.cbb_devisesTo.addItems(sorted(list(self.c.currencies))) 36 | self.cbb_devisesFrom.setCurrentText("EUR") 37 | self.cbb_devisesTo.setCurrentText("EUR") 38 | self.le_montant.setValue(100) 39 | self.le_montantConverti.setValue(100) 40 | self.le_montant.setRange(1, 1000000) 41 | self.le_montantConverti.setRange(1, 1000000) 42 | 43 | def compute(self): 44 | montant = self.le_montant.value() 45 | deviseFrom = self.cbb_devisesFrom.currentText() 46 | deviseTo = self.cbb_devisesTo.currentText() 47 | 48 | try: 49 | resultat = self.c.convert(montant, deviseFrom, deviseTo) 50 | except currency_converter.currency_converter.RateNotFoundError: 51 | print("Rate not found") 52 | else: 53 | self.le_montantConverti.setValue(resultat) 54 | 55 | def inverser_devises(self): 56 | devise_from = self.cbb_devisesFrom.currentText() 57 | devise_to = self.cbb_devisesTo.currentText() 58 | 59 | self.cbb_devisesFrom.setCurrentText(devise_to) 60 | self.cbb_devisesTo.setCurrentText(devise_from) 61 | self.compute() 62 | 63 | app = QtWidgets.QApplication([]) 64 | win = App() 65 | win.show() 66 | app.exec_() -------------------------------------------------------------------------------- /Section 45/Session 198/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtGui, QtCore 2 | import currency_converter 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.c = currency_converter.CurrencyConverter() 8 | self.setWindowTitle("Convertisseur de devises") 9 | self.setup_ui() 10 | self.setup_connections() 11 | self.set_default_values() 12 | self.setup_css() 13 | self.resize(500, 50) 14 | 15 | def setup_ui(self): 16 | self.layout = QtWidgets.QHBoxLayout(self) 17 | self.cbb_devisesFrom = QtWidgets.QComboBox() 18 | self.le_montant = QtWidgets.QSpinBox() 19 | self.cbb_devisesTo = QtWidgets.QComboBox() 20 | self.le_montantConverti = QtWidgets.QSpinBox() 21 | self.btn_inverser = QtWidgets.QPushButton("Inverser devises") 22 | 23 | self.layout.addWidget(self.cbb_devisesFrom) 24 | self.layout.addWidget(self.le_montant) 25 | self.layout.addWidget(self.cbb_devisesTo) 26 | self.layout.addWidget(self.le_montantConverti) 27 | self.layout.addWidget(self.btn_inverser) 28 | 29 | def setup_connections(self): 30 | self.cbb_devisesFrom.activated.connect(self.compute) 31 | self.cbb_devisesTo.activated.connect(self.compute) 32 | self.le_montant.valueChanged.connect(self.compute) 33 | self.btn_inverser.clicked.connect(self.inverser_devises) 34 | 35 | def setup_css(self): 36 | self.setStyleSheet(""" 37 | background-color: rgb(30, 30, 30); 38 | color: rgb(240, 240, 240); 39 | border: none; 40 | """) 41 | style = """ 42 | QComboBox::down-arrow { 43 | image: none; 44 | border-width: 0px; 45 | } 46 | QComboBox::drop-down { 47 | border-width: 0px; 48 | } 49 | """ 50 | self.cbb_devisesFrom.setStyleSheet(style) 51 | self.cbb_devisesTo.setStyleSheet(style) 52 | 53 | def set_default_values(self): 54 | self.cbb_devisesFrom.addItems(sorted(list(self.c.currencies))) 55 | self.cbb_devisesTo.addItems(sorted(list(self.c.currencies))) 56 | self.cbb_devisesFrom.setCurrentText("EUR") 57 | self.cbb_devisesTo.setCurrentText("EUR") 58 | self.le_montant.setValue(100) 59 | self.le_montantConverti.setValue(100) 60 | self.le_montant.setRange(1, 1000000) 61 | self.le_montantConverti.setRange(1, 1000000) 62 | 63 | def compute(self): 64 | montant = self.le_montant.value() 65 | deviseFrom = self.cbb_devisesFrom.currentText() 66 | deviseTo = self.cbb_devisesTo.currentText() 67 | 68 | try: 69 | resultat = self.c.convert(montant, deviseFrom, deviseTo) 70 | except currency_converter.currency_converter.RateNotFoundError: 71 | print("Rate not found") 72 | else: 73 | self.le_montantConverti.setValue(resultat) 74 | 75 | def inverser_devises(self): 76 | devise_from = self.cbb_devisesFrom.currentText() 77 | devise_to = self.cbb_devisesTo.currentText() 78 | 79 | self.cbb_devisesFrom.setCurrentText(devise_to) 80 | self.cbb_devisesTo.setCurrentText(devise_from) 81 | self.compute() 82 | 83 | app = QtWidgets.QApplication([]) 84 | win = App() 85 | win.show() 86 | app.exec_() -------------------------------------------------------------------------------- /Section 46/Session 202/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 46/Session 202/app.py -------------------------------------------------------------------------------- /Section 46/Session 202/data/movies.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 46/Session 202/data/movies.json -------------------------------------------------------------------------------- /Section 46/Session 202/movie.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 46/Session 202/movie.py -------------------------------------------------------------------------------- /Section 46/Session 206/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 46/Session 206/app.py -------------------------------------------------------------------------------- /Section 46/Session 206/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 46/Session 206/movie.py: -------------------------------------------------------------------------------- 1 | class Movie: 2 | def __init__(self, title): 3 | self.title = title.title() 4 | 5 | def __str__(self): 6 | return self.title 7 | 8 | if __name__ == "__main__": 9 | m = Movie("harry potter") 10 | print(m) -------------------------------------------------------------------------------- /Section 46/Session 208/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 46/Session 208/app.py -------------------------------------------------------------------------------- /Section 46/Session 208/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 46/Session 208/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | class Movie: 8 | def __init__(self, title): 9 | self.title = title.title() 10 | 11 | def __str__(self): 12 | return self.title 13 | 14 | def _get_movies(self): 15 | with open(DATA_FILE, "r") as f: 16 | return json.load(f) 17 | 18 | def _write_movies(self, movies): 19 | with open(DATA_FILE, "w") as f: 20 | json.dump(movies, f, indent=4) 21 | 22 | if __name__ == "__main__": 23 | m = Movie("harry potter") 24 | m._get_movies() 25 | m._write_movies() 26 | 27 | # m.add_to_movies() 28 | # m.remove_from_movies() -------------------------------------------------------------------------------- /Section 46/Session 210/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 46/Session 210/app.py -------------------------------------------------------------------------------- /Section 46/Session 210/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 46/Session 210/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | class Movie: 8 | def __init__(self, title): 9 | self.title = title.title() 10 | 11 | def __str__(self): 12 | return self.title 13 | 14 | def _get_movies(self): 15 | with open(DATA_FILE, "r") as f: 16 | return json.load(f) 17 | 18 | def _write_movies(self, movies): 19 | with open(DATA_FILE, "w") as f: 20 | json.dump(movies, f, indent=4) 21 | 22 | def add_to_movies(self): 23 | movies = self._get_movies() 24 | 25 | if self.title not in movies: 26 | movies.append(self.title) 27 | self._write_movies(movies) 28 | return True 29 | else: 30 | print(f"Le film {self.title} est déjà enregistré.") 31 | return False 32 | 33 | if __name__ == "__main__": 34 | m = Movie("harry potter") -------------------------------------------------------------------------------- /Section 46/Session 212/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 46/Session 212/app.py -------------------------------------------------------------------------------- /Section 46/Session 212/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 46/Session 212/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | class Movie: 8 | def __init__(self, title): 9 | self.title = title.title() 10 | 11 | def __str__(self): 12 | return self.title 13 | 14 | def _get_movies(self): 15 | with open(DATA_FILE, "r") as f: 16 | return json.load(f) 17 | 18 | def _write_movies(self, movies): 19 | with open(DATA_FILE, "w") as f: 20 | json.dump(movies, f, indent=4) 21 | 22 | def add_to_movies(self): 23 | movies = self._get_movies() 24 | 25 | if self.title not in movies: 26 | movies.append(self.title) 27 | self._write_movies(movies) 28 | return True 29 | else: 30 | print(f"Le film {self.title} est déjà enregistré.") 31 | return False 32 | 33 | def remove_from_movies(self): 34 | movies = self._get_movies() 35 | 36 | if self.title in movies: 37 | movies.remove(self.title) 38 | self._write_movies(movies) 39 | 40 | if __name__ == "__main__": 41 | m = Movie("harry potter") 42 | m.remove_from_movies() -------------------------------------------------------------------------------- /Section 46/Session 214/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThibH/formation-developpeur-python/74c664d5d6112009a763858f141b82055d37ac7f/Section 46/Session 214/app.py -------------------------------------------------------------------------------- /Section 46/Session 214/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 46/Session 214/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | def get_movies(): 8 | movies_instances = [] 9 | with open(DATA_FILE, "r") as f: 10 | movies = json.load(f) 11 | for movie_title in movies: 12 | movies_instances.append(Movie(movie_title)) 13 | 14 | return movies_instances 15 | 16 | class Movie: 17 | def __init__(self, title): 18 | self.title = title.title() 19 | 20 | def __str__(self): 21 | return self.title 22 | 23 | def _get_movies(self): 24 | with open(DATA_FILE, "r") as f: 25 | return json.load(f) 26 | 27 | def _write_movies(self, movies): 28 | with open(DATA_FILE, "w") as f: 29 | json.dump(movies, f, indent=4) 30 | 31 | def add_to_movies(self): 32 | movies = self._get_movies() 33 | 34 | if self.title not in movies: 35 | movies.append(self.title) 36 | self._write_movies(movies) 37 | return True 38 | else: 39 | print(f"Le film {self.title} est déjà enregistré.") 40 | return False 41 | 42 | def remove_from_movies(self): 43 | movies = self._get_movies() 44 | 45 | if self.title in movies: 46 | movies.remove(self.title) 47 | self._write_movies(movies) 48 | 49 | if __name__ == "__main__": 50 | get_movies() -------------------------------------------------------------------------------- /Section 47/Session 216/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtCore 2 | 3 | class App(QtWidgets.QWidget): 4 | def __init__(self): 5 | super().__init__() 6 | self.setWindowTitle("Ciné Club") 7 | self.setup_ui() 8 | 9 | def setup_ui(self): 10 | self.main_layout = QtWidgets.QVBoxLayout(self) 11 | 12 | self.le_movieTitle = QtWidgets.QLineEdit() 13 | self.btn_addMovie = QtWidgets.QPushButton("Ajouter un film") 14 | self.lw_movies = QtWidgets.QListWidget() 15 | self.lw_movies.setSelectionMode(QtWidgets.QListWidget.ExtendedSelection) 16 | self.btn_removeMovie = QtWidgets.QPushButton("Supprimer le(s) film(s)") 17 | 18 | self.main_layout.addWidget(self.le_movieTitle) 19 | self.main_layout.addWidget(self.btn_addMovie) 20 | self.main_layout.addWidget(self.lw_movies) 21 | self.main_layout.addWidget(self.btn_removeMovie) 22 | 23 | 24 | app = QtWidgets.QApplication([]) 25 | win = App() 26 | win.show() 27 | app.exec_() -------------------------------------------------------------------------------- /Section 47/Session 216/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 47/Session 216/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | def get_movies(): 8 | movies_instances = [] 9 | with open(DATA_FILE, "r") as f: 10 | movies = json.load(f) 11 | for movie_title in movies: 12 | movies_instances.append(Movie(movie_title)) 13 | 14 | return movies_instances 15 | 16 | class Movie: 17 | def __init__(self, title): 18 | self.title = title.title() 19 | 20 | def __str__(self): 21 | return self.title 22 | 23 | def _get_movies(self): 24 | with open(DATA_FILE, "r") as f: 25 | return json.load(f) 26 | 27 | def _write_movies(self, movies): 28 | with open(DATA_FILE, "w") as f: 29 | json.dump(movies, f, indent=4) 30 | 31 | def add_to_movies(self): 32 | movies = self._get_movies() 33 | 34 | if self.title not in movies: 35 | movies.append(self.title) 36 | self._write_movies(movies) 37 | return True 38 | else: 39 | print(f"Le film {self.title} est déjà enregistré.") 40 | return False 41 | 42 | def remove_from_movies(self): 43 | movies = self._get_movies() 44 | 45 | if self.title in movies: 46 | movies.remove(self.title) 47 | self._write_movies(movies) 48 | 49 | if __name__ == "__main__": 50 | m = Movie("harry potter") 51 | m.remove_from_movies() -------------------------------------------------------------------------------- /Section 47/Session 218/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtCore 2 | from movie import Movie, get_movies 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.setWindowTitle("Ciné Club") 8 | self.setup_ui() 9 | self.populate_movies() 10 | 11 | def setup_ui(self): 12 | self.main_layout = QtWidgets.QVBoxLayout(self) 13 | 14 | self.le_movieTitle = QtWidgets.QLineEdit() 15 | self.btn_addMovie = QtWidgets.QPushButton("Ajouter un film") 16 | self.lw_movies = QtWidgets.QListWidget() 17 | self.lw_movies.setSelectionMode(QtWidgets.QListWidget.ExtendedSelection) 18 | self.btn_removeMovie = QtWidgets.QPushButton("Supprimer le(s) film(s)") 19 | 20 | self.main_layout.addWidget(self.le_movieTitle) 21 | self.main_layout.addWidget(self.btn_addMovie) 22 | self.main_layout.addWidget(self.lw_movies) 23 | self.main_layout.addWidget(self.btn_removeMovie) 24 | 25 | def populate_movies(self): 26 | self.lw_movies.clear() 27 | movies = get_movies() 28 | for movie in movies: 29 | lw_item = QtWidgets.QListWidgetItem(movie.title) 30 | lw_item.setData(QtCore.Qt.UserRole, movie) 31 | self.lw_movies.addItem(lw_item) 32 | 33 | app = QtWidgets.QApplication([]) 34 | win = App() 35 | win.show() 36 | app.exec_() -------------------------------------------------------------------------------- /Section 47/Session 218/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 47/Session 218/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | def get_movies(): 8 | movies_instances = [] 9 | with open(DATA_FILE, "r") as f: 10 | movies = json.load(f) 11 | for movie_title in movies: 12 | movies_instances.append(Movie(movie_title)) 13 | 14 | return movies_instances 15 | 16 | class Movie: 17 | def __init__(self, title): 18 | self.title = title.title() 19 | 20 | def __str__(self): 21 | return self.title 22 | 23 | def _get_movies(self): 24 | with open(DATA_FILE, "r") as f: 25 | return json.load(f) 26 | 27 | def _write_movies(self, movies): 28 | with open(DATA_FILE, "w") as f: 29 | json.dump(movies, f, indent=4) 30 | 31 | def add_to_movies(self): 32 | movies = self._get_movies() 33 | 34 | if self.title not in movies: 35 | movies.append(self.title) 36 | self._write_movies(movies) 37 | return True 38 | else: 39 | print(f"Le film {self.title} est déjà enregistré.") 40 | return False 41 | 42 | def remove_from_movies(self): 43 | movies = self._get_movies() 44 | 45 | if self.title in movies: 46 | movies.remove(self.title) 47 | self._write_movies(movies) 48 | 49 | if __name__ == "__main__": 50 | m = Movie("harry potter") 51 | m.remove_from_movies() -------------------------------------------------------------------------------- /Section 47/Session 220/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtCore 2 | from movie import Movie, get_movies 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.setWindowTitle("Ciné Club") 8 | self.setup_ui() 9 | self.setup_connections() 10 | self.populate_movies() 11 | 12 | def setup_ui(self): 13 | self.main_layout = QtWidgets.QVBoxLayout(self) 14 | 15 | self.le_movieTitle = QtWidgets.QLineEdit() 16 | self.btn_addMovie = QtWidgets.QPushButton("Ajouter un film") 17 | self.lw_movies = QtWidgets.QListWidget() 18 | self.lw_movies.setSelectionMode(QtWidgets.QListWidget.ExtendedSelection) 19 | self.btn_removeMovie = QtWidgets.QPushButton("Supprimer le(s) film(s)") 20 | 21 | self.main_layout.addWidget(self.le_movieTitle) 22 | self.main_layout.addWidget(self.btn_addMovie) 23 | self.main_layout.addWidget(self.lw_movies) 24 | self.main_layout.addWidget(self.btn_removeMovie) 25 | 26 | def setup_connections(self): 27 | self.btn_addMovie.clicked.connect(self.add_movie) 28 | self.le_movieTitle.returnPressed.connect(self.add_movie) 29 | self.btn_removeMovie.clicked.connect(self.remove_movie) 30 | 31 | def populate_movies(self): 32 | self.lw_movies.clear() 33 | movies = get_movies() 34 | for movie in movies: 35 | lw_item = QtWidgets.QListWidgetItem(movie.title) 36 | lw_item.setData(QtCore.Qt.UserRole, movie) 37 | self.lw_movies.addItem(lw_item) 38 | 39 | def add_movie(self): 40 | print("On ajoute un film") 41 | 42 | def remove_movie(self): 43 | print("On supprime un film") 44 | 45 | app = QtWidgets.QApplication([]) 46 | win = App() 47 | win.show() 48 | app.exec_() -------------------------------------------------------------------------------- /Section 47/Session 220/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 47/Session 220/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | def get_movies(): 8 | movies_instances = [] 9 | with open(DATA_FILE, "r") as f: 10 | movies = json.load(f) 11 | for movie_title in movies: 12 | movies_instances.append(Movie(movie_title)) 13 | 14 | return movies_instances 15 | 16 | class Movie: 17 | def __init__(self, title): 18 | self.title = title.title() 19 | 20 | def __str__(self): 21 | return self.title 22 | 23 | def _get_movies(self): 24 | with open(DATA_FILE, "r") as f: 25 | return json.load(f) 26 | 27 | def _write_movies(self, movies): 28 | with open(DATA_FILE, "w") as f: 29 | json.dump(movies, f, indent=4) 30 | 31 | def add_to_movies(self): 32 | movies = self._get_movies() 33 | 34 | if self.title not in movies: 35 | movies.append(self.title) 36 | self._write_movies(movies) 37 | return True 38 | else: 39 | print(f"Le film {self.title} est déjà enregistré.") 40 | return False 41 | 42 | def remove_from_movies(self): 43 | movies = self._get_movies() 44 | 45 | if self.title in movies: 46 | movies.remove(self.title) 47 | self._write_movies(movies) 48 | 49 | if __name__ == "__main__": 50 | m = Movie("harry potter") 51 | m.remove_from_movies() -------------------------------------------------------------------------------- /Section 47/Session 222/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtCore 2 | from movie import Movie, get_movies 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.setWindowTitle("Ciné Club") 8 | self.setup_ui() 9 | self.setup_connections() 10 | self.populate_movies() 11 | 12 | def setup_ui(self): 13 | self.main_layout = QtWidgets.QVBoxLayout(self) 14 | 15 | self.le_movieTitle = QtWidgets.QLineEdit() 16 | self.btn_addMovie = QtWidgets.QPushButton("Ajouter un film") 17 | self.lw_movies = QtWidgets.QListWidget() 18 | self.lw_movies.setSelectionMode(QtWidgets.QListWidget.ExtendedSelection) 19 | self.btn_removeMovie = QtWidgets.QPushButton("Supprimer le(s) film(s)") 20 | 21 | self.main_layout.addWidget(self.le_movieTitle) 22 | self.main_layout.addWidget(self.btn_addMovie) 23 | self.main_layout.addWidget(self.lw_movies) 24 | self.main_layout.addWidget(self.btn_removeMovie) 25 | 26 | def setup_connections(self): 27 | self.btn_addMovie.clicked.connect(self.add_movie) 28 | self.le_movieTitle.returnPressed.connect(self.add_movie) 29 | self.btn_removeMovie.clicked.connect(self.remove_movie) 30 | 31 | def populate_movies(self): 32 | self.lw_movies.clear() 33 | movies = get_movies() 34 | for movie in movies: 35 | lw_item = QtWidgets.QListWidgetItem(movie.title) 36 | lw_item.setData(QtCore.Qt.UserRole, movie) 37 | self.lw_movies.addItem(lw_item) 38 | 39 | def add_movie(self): 40 | movie_title = self.le_movieTitle.text() 41 | if not movie_title: 42 | return False 43 | 44 | movie = Movie(title=movie_title) 45 | result = movie.add_to_movies() 46 | if result: 47 | lw_item = QtWidgets.QListWidgetItem(movie.title) 48 | lw_item.setData(QtCore.Qt.UserRole, movie) 49 | self.lw_movies.addItem(lw_item) 50 | self.le_movieTitle.setText("") 51 | 52 | def remove_movie(self): 53 | print("On supprime un film") 54 | 55 | app = QtWidgets.QApplication([]) 56 | win = App() 57 | win.show() 58 | app.exec_() -------------------------------------------------------------------------------- /Section 47/Session 222/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 47/Session 222/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | def get_movies(): 8 | movies_instances = [] 9 | with open(DATA_FILE, "r") as f: 10 | movies = json.load(f) 11 | for movie_title in movies: 12 | movies_instances.append(Movie(movie_title)) 13 | 14 | return movies_instances 15 | 16 | class Movie: 17 | def __init__(self, title): 18 | self.title = title.title() 19 | 20 | def __str__(self): 21 | return self.title 22 | 23 | def _get_movies(self): 24 | with open(DATA_FILE, "r") as f: 25 | return json.load(f) 26 | 27 | def _write_movies(self, movies): 28 | with open(DATA_FILE, "w") as f: 29 | json.dump(movies, f, indent=4) 30 | 31 | def add_to_movies(self): 32 | movies = self._get_movies() 33 | 34 | if self.title not in movies: 35 | movies.append(self.title) 36 | self._write_movies(movies) 37 | return True 38 | else: 39 | print(f"Le film {self.title} est déjà enregistré.") 40 | return False 41 | 42 | def remove_from_movies(self): 43 | movies = self._get_movies() 44 | 45 | if self.title in movies: 46 | movies.remove(self.title) 47 | self._write_movies(movies) 48 | 49 | if __name__ == "__main__": 50 | m = Movie("harry potter") 51 | m.remove_from_movies() -------------------------------------------------------------------------------- /Section 47/Session 223/app.py: -------------------------------------------------------------------------------- 1 | from PySide2 import QtWidgets, QtCore 2 | from movie import Movie, get_movies 3 | 4 | class App(QtWidgets.QWidget): 5 | def __init__(self): 6 | super().__init__() 7 | self.setWindowTitle("Ciné Club") 8 | self.setup_ui() 9 | self.setup_connections() 10 | self.populate_movies() 11 | 12 | def setup_ui(self): 13 | self.main_layout = QtWidgets.QVBoxLayout(self) 14 | 15 | self.le_movieTitle = QtWidgets.QLineEdit() 16 | self.btn_addMovie = QtWidgets.QPushButton("Ajouter un film") 17 | self.lw_movies = QtWidgets.QListWidget() 18 | self.lw_movies.setSelectionMode(QtWidgets.QListWidget.ExtendedSelection) 19 | self.btn_removeMovie = QtWidgets.QPushButton("Supprimer le(s) film(s)") 20 | 21 | self.main_layout.addWidget(self.le_movieTitle) 22 | self.main_layout.addWidget(self.btn_addMovie) 23 | self.main_layout.addWidget(self.lw_movies) 24 | self.main_layout.addWidget(self.btn_removeMovie) 25 | 26 | def setup_connections(self): 27 | self.btn_addMovie.clicked.connect(self.add_movie) 28 | self.le_movieTitle.returnPressed.connect(self.add_movie) 29 | self.btn_removeMovie.clicked.connect(self.remove_movie) 30 | 31 | def populate_movies(self): 32 | self.lw_movies.clear() 33 | movies = get_movies() 34 | for movie in movies: 35 | lw_item = QtWidgets.QListWidgetItem(movie.title) 36 | lw_item.setData(QtCore.Qt.UserRole, movie) 37 | self.lw_movies.addItem(lw_item) 38 | 39 | def add_movie(self): 40 | movie_title = self.le_movieTitle.text() 41 | if not movie_title: 42 | return False 43 | 44 | movie = Movie(title=movie_title) 45 | result = movie.add_to_movies() 46 | if result: 47 | lw_item = QtWidgets.QListWidgetItem(movie.title) 48 | lw_item.setData(QtCore.Qt.UserRole, movie) 49 | self.lw_movies.addItem(lw_item) 50 | self.le_movieTitle.setText("") 51 | 52 | def remove_movie(self): 53 | for selected_item in self.lw_movies.selectedItems(): 54 | movie = selected_item.data(QtCore.Qt.UserRole) 55 | movie.remove_from_movies() 56 | self.lw_movies.takeItem(self.lw_movies.row(selected_item)) 57 | 58 | app = QtWidgets.QApplication([]) 59 | win = App() 60 | win.show() 61 | app.exec_() -------------------------------------------------------------------------------- /Section 47/Session 223/data/movies.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Harry Potter", 3 | "Spider Man" 4 | ] -------------------------------------------------------------------------------- /Section 47/Session 223/movie.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | CUR_DIR = os.path.dirname(__file__) 5 | DATA_FILE = os.path.join(CUR_DIR, "data", "movies.json") 6 | 7 | def get_movies(): 8 | movies_instances = [] 9 | with open(DATA_FILE, "r") as f: 10 | movies = json.load(f) 11 | for movie_title in movies: 12 | movies_instances.append(Movie(movie_title)) 13 | 14 | return movies_instances 15 | 16 | class Movie: 17 | def __init__(self, title): 18 | self.title = title.title() 19 | 20 | def __str__(self): 21 | return self.title 22 | 23 | def _get_movies(self): 24 | with open(DATA_FILE, "r") as f: 25 | return json.load(f) 26 | 27 | def _write_movies(self, movies): 28 | with open(DATA_FILE, "w") as f: 29 | json.dump(movies, f, indent=4) 30 | 31 | def add_to_movies(self): 32 | movies = self._get_movies() 33 | 34 | if self.title not in movies: 35 | movies.append(self.title) 36 | self._write_movies(movies) 37 | return True 38 | else: 39 | print(f"Le film {self.title} est déjà enregistré.") 40 | return False 41 | 42 | def remove_from_movies(self): 43 | movies = self._get_movies() 44 | 45 | if self.title in movies: 46 | movies.remove(self.title) 47 | self._write_movies(movies) 48 | 49 | if __name__ == "__main__": 50 | m = Movie("harry potter") 51 | m.remove_from_movies() --------------------------------------------------------------------------------