├── .gitignore ├── 00-Objets et structures de données Python de Base ├── 01-Les nombres.ipynb ├── 02-Les chaines de caractères.ipynb ├── 03-Affichage et sortie écran.ipynb ├── 04-Les listes.ipynb ├── 05-Les dictionnaires.ipynb ├── 06-Les Sets et les Booléens.ipynb ├── 07-Tuples.ipynb ├── 08-Les fichiers.ipynb ├── 09-Controle de connaissances sur les objets et les structures de données.ipynb ├── 10-Solutions du controle de connaissances sur les objets et les structures de données.ipynb └── test.txt ├── 01-Python opérateurs de comparaison ├── 01-Comparison Operators.ipynb ├── 02-Chained Comparison Operators.ipynb ├── 02-Opérateurs logiques.ipynb └── 03-Enchainement d'opérateurs logiques.ipynb ├── 02-Python Déclarations ├── 01-Introduction aux instructions Python.ipynb ├── 04-Les directives if, elif, et else.ipynb ├── 05-Boucles for.ipynb ├── 06-Boucles while.ipynb ├── 07-Range().ipynb ├── 08-Listes en compréhension.ipynb ├── Contrôle des connaissances.ipynb └── Solutions du contrôle des connaissances.ipynb ├── 03-Méthodes et Fonctions ├── 01-Les fonctions.ipynb ├── 02-Les méthodes.ipynb ├── 03-Les instructions imbriquées et le "Scope".ipynb ├── 04-Les expressions lambda.ipynb ├── 05-Fonctions - arguments par défaut.ipynb ├── Controle de connaissances sur les fonctions et les méthodes.ipynb └── Solution du controle de connaissances sur les fonctions et les méthodes.ipynb ├── 04-Premier Projet ├── 1 - Présentation du premier project.ipynb ├── 2 - Premier Projet d'étape - Feuille de route détaillée.ipynb ├── 3 - Solution de la feuille de route du jeu de Morpion.ipynb ├── 4 - Solution améliorée de la feuille de route du jeu de Morpion.ipynb └── Pas utilisé dans la version en ligne - Solution du jeu de Morpion.ipynb ├── 05-Programmation Orientée Objet ├── Programmation Orientée Objet - Contrôle de connaissances - Solution.ipynb ├── Programmation Orientée Objet - Contrôle de connaissances.ipynb └── Programmation Orientée Objet.ipynb ├── 06-Modules et Paquets ├── 00-Modules_and_Packages │ ├── MyMainPackage │ │ ├── SubPackage │ │ │ ├── __init__.py │ │ │ ├── __pycache__ │ │ │ │ ├── __init__.cpython-36.pyc │ │ │ │ └── mysubscript.cpython-36.pyc │ │ │ └── mysubscript.py │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-36.pyc │ │ │ └── some_main_script.cpython-36.pyc │ │ └── some_main_script.py │ ├── mymodule.py │ └── myprogram.py ├── 01-Name_and_Main │ ├── Explanation.txt │ ├── one.py │ └── two.py └── Modules et Paquets.ipynb ├── 07-Erreurs et Exceptions ├── Gestion des erreurs et des exceptions - Controle de connaissances.ipynb ├── Gestion des erreurs et des exceptions - Solution du controle de connaissances.ipynb └── Gestion des erreurs et des exceptions.ipynb ├── 08-Deuxième Projet ├── Milestone Project 2 - Développer un jeu de Blackjack.ipynb └── Milestone Project 2 Solution.ipynb ├── 09-Fonctions Intégrées ├── All() et any().ipynb ├── Complex.ipynb ├── Controle de connaissances sur les fonctions intégrées.ipynb ├── Enumerate.ipynb ├── Filter.ipynb ├── Map.ipynb ├── Solutions du controle de connaissances sur les fonctions intégrées.ipynb └── Zip.ipynb ├── 10-Décorateurs ├── Approfondissements sur les décorateurs .ipynb └── Decorateurs.ipynb ├── 11-Itérateurs et Générateurs ├── Devoir sur les iterateurs et les générateurs - Solution.ipynb ├── Devoir sur les iterateurs et les générateurs.ipynb └── Iterateurs et générateurs.ipynb ├── 12-Modules Python avancés ├── 00-Module Collection.ipynb ├── 01-Accéder à des fichiers et des dossiers.ipynb ├── 02-Module Datetime.ipynb ├── 03-Modules Math et Random.ipynb ├── 04-Python Debugger (pdb).ipynb ├── 05-Expressions régulières.ipynb ├── 06-Minutage et chronométrage de votre code - timeit.ipynb ├── 07-décompresser et compresser des fichiers (ZIP).ipynb ├── 08-Exercices sur les modules Python avancés │ ├── 07-Advanced-Modules-Exercise-Puzzle.ipynb │ ├── 08-Advanced-Modules-Exercise-Solutions.ipynb │ └── unzip_me_for_instructions.zip └── Exemple_Dossier_Racine │ ├── Exemple-Haut-un │ ├── Document-Niveau-Moyen.txt │ ├── Niveau-Moyen-Deux │ │ └── Text-Niveau-Profond.txt │ └── Niveau-Moyen-Un │ │ └── Un_texte.txt │ └── Exemple-Haut.txt ├── 13-Web Scraping ├── 00-Guide-du-Web-Scraping.ipynb ├── 01-Exercises-de-Web-Scraping.ipynb ├── 02-Solutions des Exercices de Web Scraping.ipynb └── mon_nouveau_fichier_image.jpg ├── 14-Travailler avec des images ├── 00-Les grandes lignes du module travailler avec des images.ipynb ├── 01-Exercice sur les images.ipynb ├── 02-Solution de l'exercice sur les images.ipynb ├── blue_color.png ├── crayons.jpg ├── exemple.jpg ├── masque.png ├── matrice_de_mots.png ├── mauve.png ├── rouge.jpg └── word_matrix.png ├── 15-PDFs et tableaux de données ├── 00-Travailler avec des fichiers CSV.ipynb ├── 01-Working-with-PDFs.ipynb ├── 02-PDFs-Spreadsheets-Puzzle.ipynb ├── 03-PDFs-Spreadsheets-Puzzle-Solution.ipynb ├── Exercise_Files │ ├── Find_the_Phone_Number.pdf │ └── find_the_link.csv ├── Some_BrandNew_Doc.pdf ├── Some_New_Doc.pdf ├── Some_new_file.pdf ├── Working_Business_Proposal.pdf ├── exemple.csv ├── fichier_à_sauver.csv ├── makeup_new.csv └── to_save_file.csv ├── 16-Envoi d'emails avec Python ├── 00-Overview-of-Sending-Emails.ipynb ├── 01-Overview-of-Received-Emails.ipynb └── 02-Exercise-Ideas.ipynb ├── 17-Objets et structures de données Python avancés ├── 01-Advanced Numbers.ipynb ├── 02-Advanced Strings.ipynb ├── 03-Advanced Sets.ipynb ├── 04-Advanced Dictionaries.ipynb ├── 05-Advanced Lists.ipynb ├── 06-Advanced Python Objects Test.ipynb ├── 07-Advanced Python Objects Test - Solutions.ipynb └── 08-BONUS - With Statement Context Managers.ipynb ├── 18-Troisième projet ├── 01-Quelques idées pour votre projet final.ipynb └── 02-Solutions réalisées par les participants du cours US.ipynb ├── 19-Bonus - Introduction aux interfaces graphiques (GUI) ├── 01-Interact.ipynb ├── 02-Widget Basics.ipynb ├── 03-Widget List.ipynb ├── 04-Widget Events.ipynb ├── 05-Widget Styling.ipynb ├── 06-Custom Widget.ipynb ├── 07-Advanced Widget List.ipynb └── 08-Advanced Widget Styling with Layout.ipynb ├── 99-a positionner ├── 06_StringIO.ipynb └── 07_MultiProcessing.ipynb ├── FAQ.ipynb ├── Jupyter (iPython) Notebooks Guide.ipynb ├── Mon bloc note.ipynb ├── Mon premier bloc note.ipynb ├── Pierian_Data_Logo.png ├── README.md └── logo_XDM.png /00-Objets et structures de données Python de Base/06-Les Sets et les Booléens.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | "\n", 10 | "\n", 11 | "___\n", 12 | "
Content Copyright by Pierian Data and xDM Consulting
" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Les Sets et les Booléens\n", 20 | "\n", 21 | "Il reste deux autres types d'objets Python que nous devons rapidement voir. Les Sets et les Booléens.\n", 22 | "\n", 23 | "## Sets\n", 24 | "\n", 25 | "Les Sets sont des collections non triées d'éléments *unique*. Nous pouvons les créer avec la fonction set().\n", 26 | "Voyons comment les utiliser." 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 1, 32 | "metadata": { 33 | "collapsed": true 34 | }, 35 | "outputs": [], 36 | "source": [ 37 | "x = set()" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 3, 43 | "metadata": { 44 | "collapsed": true 45 | }, 46 | "outputs": [], 47 | "source": [ 48 | "# Nous pouvons ajouter des éléments avec la méthode add\n", 49 | "x.add(1)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 4, 55 | "metadata": {}, 56 | "outputs": [ 57 | { 58 | "data": { 59 | "text/plain": [ 60 | "{1}" 61 | ] 62 | }, 63 | "execution_count": 4, 64 | "metadata": {}, 65 | "output_type": "execute_result" 66 | } 67 | ], 68 | "source": [ 69 | "# Visualiser le contenu\n", 70 | "x" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "Remarquez les accolades. Il ne faut pourtant pas confondre avec un dictionnaire ! Vous pouvez au mieux trouver une analogie avec un dictionnaire qui ne contiendrait que des clefs.\n", 78 | "\n", 79 | "Nous avons dit que les éléments d'un set sont uniques. Que se passe-t-il quand on essaie d'ajouter quelque chose qui existe déjà dans le set ?\n" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 5, 85 | "metadata": { 86 | "collapsed": true 87 | }, 88 | "outputs": [], 89 | "source": [ 90 | "# Ajouter un élement différent\n", 91 | "x.add(2)" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 6, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "data": { 101 | "text/plain": [ 102 | "{1, 2}" 103 | ] 104 | }, 105 | "execution_count": 6, 106 | "metadata": {}, 107 | "output_type": "execute_result" 108 | } 109 | ], 110 | "source": [ 111 | "# Visualiser le contenu\n", 112 | "x" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 7, 118 | "metadata": { 119 | "collapsed": true 120 | }, 121 | "outputs": [], 122 | "source": [ 123 | "# Essaye d'ajouter un élément déjà présent\n", 124 | "x.add(1)" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 9, 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "data": { 134 | "text/plain": [ 135 | "{1, 2}" 136 | ] 137 | }, 138 | "execution_count": 9, 139 | "metadata": {}, 140 | "output_type": "execute_result" 141 | } 142 | ], 143 | "source": [ 144 | "# Visualiser le contenu\n", 145 | "x" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "metadata": {}, 151 | "source": [ 152 | "Remarquez qu'il n'y a pas eu l'ajout d'un autre élément 1 ici. C'est parce que le set ne contient que des éléments uniques ! Il est possible d'intégrer une liste avec des éléments dupliqués dans un set pour isoler les éléments distincts.\n", 153 | "Par exemple : " 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 10, 159 | "metadata": { 160 | "collapsed": true 161 | }, 162 | "outputs": [], 163 | "source": [ 164 | "# Crée une liste avec des éléments dupliqués\n", 165 | "l = [1,1,2,2,3,4,5,6,1,1]" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 12, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "data": { 175 | "text/plain": [ 176 | "{1, 2, 3, 4, 5, 6}" 177 | ] 178 | }, 179 | "execution_count": 12, 180 | "metadata": {}, 181 | "output_type": "execute_result" 182 | } 183 | ], 184 | "source": [ 185 | "# Redéfinie en set pour isoler les éléments uniques\n", 186 | "set(l)" 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": {}, 192 | "source": [ 193 | "## Booléens\n", 194 | "\n", 195 | "Python intègre des variables logiques ou Booléens (avec des noms True et False prédéfinis qui ne sont en fait qu'une représentation des entiers 1 et 0). Il existe aussi un objet indéfini appelé None.\n", 196 | "\n", 197 | "Voyons quelques petits exemples rapides de Booléens (nous irons plus en détails un peu plus tard dans le cours)." 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 13, 203 | "metadata": { 204 | "collapsed": true 205 | }, 206 | "outputs": [], 207 | "source": [ 208 | "# Définir un objet avec le type Booléen\n", 209 | "a = True" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 16, 215 | "metadata": {}, 216 | "outputs": [ 217 | { 218 | "data": { 219 | "text/plain": [ 220 | "True" 221 | ] 222 | }, 223 | "execution_count": 16, 224 | "metadata": {}, 225 | "output_type": "execute_result" 226 | } 227 | ], 228 | "source": [ 229 | "# Visualiser\n", 230 | "a" 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "metadata": {}, 236 | "source": [ 237 | "Nous pouvons aussi utiliser les opérateurs de comparaison pour créer un booléen. Nous verrons ces opérateurs en détail plus tard dans le cours." 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 17, 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "data": { 247 | "text/plain": [ 248 | "False" 249 | ] 250 | }, 251 | "execution_count": 17, 252 | "metadata": {}, 253 | "output_type": "execute_result" 254 | } 255 | ], 256 | "source": [ 257 | "# La sortie produite est un booléen\n", 258 | "1 > 2" 259 | ] 260 | }, 261 | { 262 | "cell_type": "markdown", 263 | "metadata": {}, 264 | "source": [ 265 | "Nous pouvons utiliser None pour réserver l'espace d'un objet booléen dont on ne connait pas encore la valeur" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 18, 271 | "metadata": { 272 | "collapsed": true 273 | }, 274 | "outputs": [], 275 | "source": [ 276 | "# Réserver l'espace avec None\n", 277 | "b = None" 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "metadata": {}, 283 | "source": [ 284 | "C'est tout !\n", 285 | "Vous avez maintenant les connaissances de base concernant les différents types d'objets et de structures de données Python. Étape suivante, le test de connaissances pour valider cette partie !" 286 | ] 287 | } 288 | ], 289 | "metadata": { 290 | "anaconda-cloud": {}, 291 | "kernelspec": { 292 | "display_name": "Python 3", 293 | "language": "python", 294 | "name": "python3" 295 | }, 296 | "language_info": { 297 | "codemirror_mode": { 298 | "name": "ipython", 299 | "version": 3 300 | }, 301 | "file_extension": ".py", 302 | "mimetype": "text/x-python", 303 | "name": "python", 304 | "nbconvert_exporter": "python", 305 | "pygments_lexer": "ipython3", 306 | "version": "3.7.7" 307 | } 308 | }, 309 | "nbformat": 4, 310 | "nbformat_minor": 1 311 | } 312 | -------------------------------------------------------------------------------- /00-Objets et structures de données Python de Base/test.txt: -------------------------------------------------------------------------------- 1 | Bonjour ceci est un petit fichier 2 | une deuxième ligne 3 | une troisième ligne 4 | 5 | une quatrième ligne 6 | et une cinquième ligne 7 | ajouter une sixième ligne -------------------------------------------------------------------------------- /01-Python opérateurs de comparaison/02-Chained Comparison Operators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | "\n", 10 | "___\n", 11 | "
Content Copyright by Pierian Data
" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "# Chained Comparison Operators\n", 19 | "\n", 20 | "An interesting feature of Python is the ability to *chain* multiple comparisons to perform a more complex test. You can use these chained comparisons as shorthand for larger Boolean Expressions.\n", 21 | "\n", 22 | "In this lecture we will learn how to chain comparison operators and we will also introduce two other important statements in Python: **and** and **or**.\n", 23 | "\n", 24 | "Let's look at a few examples of using chains:" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 1, 30 | "metadata": {}, 31 | "outputs": [ 32 | { 33 | "data": { 34 | "text/plain": [ 35 | "True" 36 | ] 37 | }, 38 | "execution_count": 1, 39 | "metadata": {}, 40 | "output_type": "execute_result" 41 | } 42 | ], 43 | "source": [ 44 | "1 < 2 < 3" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "The above statement checks if 1 was less than 2 **and** if 2 was less than 3. We could have written this using an **and** statement in Python:" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 2, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "data": { 61 | "text/plain": [ 62 | "True" 63 | ] 64 | }, 65 | "execution_count": 2, 66 | "metadata": {}, 67 | "output_type": "execute_result" 68 | } 69 | ], 70 | "source": [ 71 | "1<2 and 2<3" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "The **and** is used to make sure two checks have to be true in order for the total check to be true. Let's see another example:" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 3, 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "data": { 88 | "text/plain": [ 89 | "True" 90 | ] 91 | }, 92 | "execution_count": 3, 93 | "metadata": {}, 94 | "output_type": "execute_result" 95 | } 96 | ], 97 | "source": [ 98 | "1 < 3 > 2" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "The above checks if 3 is larger than both of the other numbers, so you could use **and** to rewrite it as:" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 4, 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "data": { 115 | "text/plain": [ 116 | "True" 117 | ] 118 | }, 119 | "execution_count": 4, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "1<3 and 3>2" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "It's important to note that Python is checking both instances of the comparisons. We can also use **or** to write comparisons in Python. For example:" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 5, 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "data": { 142 | "text/plain": [ 143 | "True" 144 | ] 145 | }, 146 | "execution_count": 5, 147 | "metadata": {}, 148 | "output_type": "execute_result" 149 | } 150 | ], 151 | "source": [ 152 | "1==2 or 2<3" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "Note how it was true; this is because with the **or** operator, we only need one *or* the other to be true. Let's see one more example to drive this home:" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": 6, 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "data": { 169 | "text/plain": [ 170 | "True" 171 | ] 172 | }, 173 | "execution_count": 6, 174 | "metadata": {}, 175 | "output_type": "execute_result" 176 | } 177 | ], 178 | "source": [ 179 | "1==1 or 100==1" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": {}, 185 | "source": [ 186 | "Great! For an overview of this quick lesson: You should have a comfortable understanding of using **and** and **or** statements as well as reading chained comparison code.\n", 187 | "\n", 188 | "Go ahead and go to the quiz for this section to check your understanding!" 189 | ] 190 | } 191 | ], 192 | "metadata": { 193 | "kernelspec": { 194 | "display_name": "Python 3", 195 | "language": "python", 196 | "name": "python3" 197 | }, 198 | "language_info": { 199 | "codemirror_mode": { 200 | "name": "ipython", 201 | "version": 3 202 | }, 203 | "file_extension": ".py", 204 | "mimetype": "text/x-python", 205 | "name": "python", 206 | "nbconvert_exporter": "python", 207 | "pygments_lexer": "ipython3", 208 | "version": "3.6.6" 209 | } 210 | }, 211 | "nbformat": 4, 212 | "nbformat_minor": 1 213 | } 214 | -------------------------------------------------------------------------------- /01-Python opérateurs de comparaison/03-Enchainement d'opérateurs logiques.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Enchainement d'opérateurs logiques\n", 8 | "\n", 9 | "Une fonctionnalité intéressante de Python est la faculté de *chainer* des comparateurs logiques pour réaliser un test complexe. Vous pouvez utiliser ces comparateur chainés comme un racourci pour des expressions booléennes plus complexes.\n", 10 | "\n", 11 | "Dans ce cours nous allons apprendre comment chainer les tests logiques et nous allons également voir deux opérateurs indispensables \"et\" **and** et \"ou\" **or**.\n", 12 | "\n", 13 | "Voyons quelques exemples :" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 1, 19 | "metadata": {}, 20 | "outputs": [ 21 | { 22 | "data": { 23 | "text/plain": [ 24 | "True" 25 | ] 26 | }, 27 | "execution_count": 1, 28 | "metadata": {}, 29 | "output_type": "execute_result" 30 | } 31 | ], 32 | "source": [ 33 | "1 < 2 < 3" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "La ligne de code précédente vérifie si 1 est inférieur à 2 **ET** si 2 est inférieur à 3. On aurait également pu l'écrire avec une instruction **and** en Python :" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 2, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "True" 52 | ] 53 | }, 54 | "execution_count": 2, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "1<2 and 2<3" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "Le **and** est utilisé pour s'assurer que les deux test logiques sont vrais de sorte que le test complet sera vrai.\n", 68 | "Voyons un autre exemple :" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 3, 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "data": { 78 | "text/plain": [ 79 | "True" 80 | ] 81 | }, 82 | "execution_count": 3, 83 | "metadata": {}, 84 | "output_type": "execute_result" 85 | } 86 | ], 87 | "source": [ 88 | "1 < 3 > 2" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "Ces tests vérifient que 3 est plus grand que les deux autres nombres, on peut donc utiliser **and** pour l'écrire aussi de cette manière :" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 4, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "data": { 105 | "text/plain": [ 106 | "True" 107 | ] 108 | }, 109 | "execution_count": 4, 110 | "metadata": {}, 111 | "output_type": "execute_result" 112 | } 113 | ], 114 | "source": [ 115 | "1<3 and 3>2" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "Il est important de noter que Python vérifie les deux instances de comparaisons. On peut aussi utiliser **or** pour écrire des tests en Python.\n", 123 | "Par exemple :" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 5, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "data": { 133 | "text/plain": [ 134 | "True" 135 | ] 136 | }, 137 | "execution_count": 5, 138 | "metadata": {}, 139 | "output_type": "execute_result" 140 | } 141 | ], 142 | "source": [ 143 | "1==2 or 2<3" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "metadata": {}, 149 | "source": [ 150 | "Remarquez que le résultat est vrai, parce qu'avec l'opérateur **or**, nous avons besoin que l'un **ou** l'autre des tests soit vrai.\n", 151 | "Regardons un autre exemple pour bien assimiler :" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 6, 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "data": { 161 | "text/plain": [ 162 | "True" 163 | ] 164 | }, 165 | "execution_count": 6, 166 | "metadata": {}, 167 | "output_type": "execute_result" 168 | } 169 | ], 170 | "source": [ 171 | "1==1 or 100==1" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "Bravo !\n", 179 | "Vous devez maintenant avoir bien compris comment utiliser les opérateurs **and** et **or** ainsi qu'être capable de lire du code de tests de comparaison chainés.\n", 180 | "\n", 181 | "Il ne vous reste plus qu'à faire le test de cette section pour valider votre apprentissage !" 182 | ] 183 | } 184 | ], 185 | "metadata": { 186 | "anaconda-cloud": {}, 187 | "kernelspec": { 188 | "display_name": "Python 3", 189 | "language": "python", 190 | "name": "python3" 191 | }, 192 | "language_info": { 193 | "codemirror_mode": { 194 | "name": "ipython", 195 | "version": 3 196 | }, 197 | "file_extension": ".py", 198 | "mimetype": "text/x-python", 199 | "name": "python", 200 | "nbconvert_exporter": "python", 201 | "pygments_lexer": "ipython3", 202 | "version": "3.6.8" 203 | } 204 | }, 205 | "nbformat": 4, 206 | "nbformat_minor": 1 207 | } 208 | -------------------------------------------------------------------------------- /02-Python Déclarations/01-Introduction aux instructions Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Introduction aux instructions Python\n", 12 | "\n", 13 | "Dans cette leçon nous allons faire une rapide introduction aux instructions Python. Nous mettrons l'accent sur les différences entre Python et d'autres langages comme C++.\n", 14 | "\n", 15 | "Il y a deux raisons pour procéder de la sorte dans l'apprentissage des instructions Python.\n", 16 | "\n", 17 | " 1.) Si vous connaissez déjà un autre langage, cela va accélérer votre apprentissage de Python.\n", 18 | " 2.) Apprendre de cette manière vous aidera à comprendre d'autres langages dans le futur." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "slideshow": { 25 | "slide_type": "slide" 26 | } 27 | }, 28 | "source": [ 29 | "## Python par rapport aux autres langages\n", 30 | "\n", 31 | "Créons une déclaration simple pour faire :\n", 32 | "\"Si a est plus grand que b, assigner 2 à a et 4 à b\"\n", 33 | "\n", 34 | "Regardez ces deux blocs d'instructions *if* (nous apprendrons comment construire des blocs if plus tard). \n", 35 | "\n", 36 | "**Version 1 (Autres langages)**\n", 37 | "\n", 38 | " if (a>b){\n", 39 | " a = 2;\n", 40 | " b = 4;\n", 41 | " }\n", 42 | " \n", 43 | "**Version 2 (Python)** \n", 44 | "\n", 45 | " if a>b:\n", 46 | " a = 2\n", 47 | " b = 4" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "Vous remarquerez que Python est moins chargé et bien plus lisible que la première version. Comment Python gère-t-il cela ?\n", 55 | "\n", 56 | "Regardons les différences principales :\n", 57 | "\n", 58 | "Python n'utilise ni () ni {} en prenant en compte deux facteurs principaux : le *deux point* et les *espaces*. L'instruction se termine par deux points, et l'indentation permet de mettre en évidence ce qui sera exécuté.\n", 59 | "\n", 60 | "Une autre différence majeure est l'absence de point virgule avec Python. Le point virgule est utilisé pour signaler la fin d'un instruction dans de nombreux langages, mais en Python, la fin de ligne signale aussi la fin d'une instruction.\n", 61 | "\n", 62 | "Pour terminer cette introduction rapide des différences, regardons de plus près la syntaxe indentée de Python par rapport à d'autres langages :\n", 63 | "\n", 64 | "## Indentation\n", 65 | "\n", 66 | "Voici quelques lignes de pseudo-code pour présenter l'usage des espaces et de l'indentation en Python :\n", 67 | "\n", 68 | "**Autres langages**\n", 69 | "\n", 70 | " if (x)\n", 71 | " if (y)\n", 72 | " ligne-de-code;\n", 73 | " else\n", 74 | " autre-ligne-de-code;\n", 75 | " \n", 76 | "**Python**\n", 77 | " \n", 78 | " if x:\n", 79 | " if y:\n", 80 | " ligne-de-code\n", 81 | " else:\n", 82 | " autre-ligne-de-code" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "Notez comment Python est piloté par l'indentation de code et les espaces. Cela signifie que la lisibilité du code est une partie essentielle de la conception du langage Python.\n", 90 | "\n", 91 | "Maintenant nous allons nous plonger plus profond en apprenant à coder ce type d'instructions en Python !" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": { 97 | "collapsed": true 98 | }, 99 | "source": [ 100 | "## C'est le moment de commencer à coder !" 101 | ] 102 | } 103 | ], 104 | "metadata": { 105 | "anaconda-cloud": {}, 106 | "kernelspec": { 107 | "display_name": "Python 3", 108 | "language": "python", 109 | "name": "python3" 110 | }, 111 | "language_info": { 112 | "codemirror_mode": { 113 | "name": "ipython", 114 | "version": 3 115 | }, 116 | "file_extension": ".py", 117 | "mimetype": "text/x-python", 118 | "name": "python", 119 | "nbconvert_exporter": "python", 120 | "pygments_lexer": "ipython3", 121 | "version": "3.6.8" 122 | } 123 | }, 124 | "nbformat": 4, 125 | "nbformat_minor": 1 126 | } 127 | -------------------------------------------------------------------------------- /02-Python Déclarations/04-Les directives if, elif, et else.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Les directives if,elif et else\n", 8 | "\n", 9 | "La directive Python *if* va nous permettre de dire au programme d'exécuter différentes actions en fonction du résultats à certain tests.\n", 10 | "\n", 11 | "\n", 12 | "Nous pouvons imaginer que nous demandons à l'ordinateur :\n", 13 | "\"Hé, si ceci se produit, exécute cette action\"\n", 14 | "\n", 15 | "Nous pouvons développer cette idée plus loin avec les directives *elif* et *else*, qui vont nous permettre de dire à l'ordinateur :\n", 16 | "\n", 17 | "\"Ohé, si ceci se produit, fait cela. Autrement, si cet autre cas se produit, fait plutôt ceci. Sinon-- aucun de ces cas ne s'est produit, fait donc cette action.\"\n", 18 | "\n", 19 | "Allons-y et jetons un coup d'oeil à la syntaxe des directives if pour avoir une idée plus précise de tout ça :\n", 20 | "\n", 21 | " if cas1:\n", 22 | " exécute action1\n", 23 | " elif cas2:\n", 24 | " exécute action2\n", 25 | " else: \n", 26 | " exécute action 3" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Premier exemple\n", 34 | "\n", 35 | "Regardons un exemple simple :" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 2, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "C'est vrai !\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "if True:\n", 53 | " print (\"C'est vrai !\")" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "Ajoutons un sinon (else) :" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 3, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "Ceci va être affiché chaque fois que x n'est pas vrai\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "x = False\n", 78 | "\n", 79 | "if x:\n", 80 | " print ('x est vrai !')\n", 81 | "else:\n", 82 | " print (\"Ceci va être affiché chaque fois que x n'est pas vrai\")" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "### Branchements multiples\n", 90 | "\n", 91 | "Maintenant, regardons jusqu'où nous pouvons aller avec if, elif, et else !\n", 92 | "\n", 93 | "Nous allons écrire une structure imbriquée. Remarquez comment le if, elif et else sont alignés. Cela devrait vous aider à comprendre quel if est en relation avec quel elif ou else.\n", 94 | "\n", 95 | "Nous allons revoir aussi la syntaxe des tests logiques avec Python." 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 8, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "name": "stdout", 105 | "output_type": "stream", 106 | "text": [ 107 | "Bienvenue à la banque!\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "loc = 'Banque'\n", 113 | "\n", 114 | "if loc == 'Magasin Auto':\n", 115 | " print ('Bienvenue au Magasin Auto!')\n", 116 | "elif loc == 'Banque':\n", 117 | " print ('Bienvenue à la banque!')\n", 118 | "else:\n", 119 | " print (\"Où es-tu?\")" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "Remarquez comment les directives if imbriquées sont vérifiées jusqu'à ce qu'un booléen True va permettre au code qui suit de s'exécuter. Vous devez aussi noter que vous pouvez ajouter autant de elif que nécessaire avant de terminer la série avec un else.\n", 127 | "\n", 128 | "Voyons deux autres exemples simples pour les directives if, elif et else :" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 9, 134 | "metadata": {}, 135 | "outputs": [ 136 | { 137 | "name": "stdout", 138 | "output_type": "stream", 139 | "text": [ 140 | "Bienvenue Sammy!\n" 141 | ] 142 | } 143 | ], 144 | "source": [ 145 | "personne = 'Sammy'\n", 146 | "\n", 147 | "if personne == 'Sammy':\n", 148 | " print ('Bienvenue Sammy!')\n", 149 | "else:\n", 150 | " print (\"Bienvenue, quel est ton nom ?\" )" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 11, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "name": "stdout", 160 | "output_type": "stream", 161 | "text": [ 162 | "Bienvenue Georges!\n" 163 | ] 164 | } 165 | ], 166 | "source": [ 167 | "personne = 'Georges'\n", 168 | "\n", 169 | "if personne == 'Sammy':\n", 170 | " print ('Bienvenue Sammy!')\n", 171 | "elif personne =='Georges':\n", 172 | " print (\"Bienvenue Georges!\")\n", 173 | "else:\n", 174 | " print (\"Bienvenue, quel est ton nom ?\" )" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": {}, 180 | "source": [ 181 | "## Indentation\n", 182 | "\n", 183 | "Il est très important de comprendre comment fonctionne l'indentation est utilisée avec Python pour maintenir la structure et l'organisation de votre code.\n", 184 | "\n", 185 | "Nous reviendrons sur ce sujet quand nous allons commencer à construire des fonctions !" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": null, 191 | "metadata": { 192 | "collapsed": true 193 | }, 194 | "outputs": [], 195 | "source": [] 196 | } 197 | ], 198 | "metadata": { 199 | "anaconda-cloud": {}, 200 | "kernelspec": { 201 | "display_name": "Python 3", 202 | "language": "python", 203 | "name": "python3" 204 | }, 205 | "language_info": { 206 | "codemirror_mode": { 207 | "name": "ipython", 208 | "version": 3 209 | }, 210 | "file_extension": ".py", 211 | "mimetype": "text/x-python", 212 | "name": "python", 213 | "nbconvert_exporter": "python", 214 | "pygments_lexer": "ipython3", 215 | "version": "3.6.8" 216 | } 217 | }, 218 | "nbformat": 4, 219 | "nbformat_minor": 1 220 | } 221 | -------------------------------------------------------------------------------- /02-Python Déclarations/07-Range().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# range()\n", 8 | "\n", 9 | "Dans cette courte leçon, nous allons découvrir la fonction range(). Nous n'avons pas encore développé une connaissance détaillée des fonctions, mais nous pouvons comprendre les bases de cette fonction simple (mais extrêmement utile!).\n", 10 | "\n", 11 | "range() nous permet de générer une liste de nombres entiers allant d'une valeur de départ *jusqu'à* une valeur de fin. Nous pouvons également spécifier la taille du pas.\n", 12 | "\n", 13 | "Voyons quelques exemples:" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 7, 19 | "metadata": {}, 20 | "outputs": [ 21 | { 22 | "data": { 23 | "text/plain": [ 24 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" 25 | ] 26 | }, 27 | "execution_count": 7, 28 | "metadata": {}, 29 | "output_type": "execute_result" 30 | } 31 | ], 32 | "source": [ 33 | "list(range(0,10))" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 3, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "range" 45 | ] 46 | }, 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "x =range(0,10)\n", 54 | "type(x)" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 4, 60 | "metadata": { 61 | "collapsed": true 62 | }, 63 | "outputs": [], 64 | "source": [ 65 | "start = 0 #Défaut\n", 66 | "stop = 20 \n", 67 | "x = range(start,stop)" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 5, 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]" 79 | ] 80 | }, 81 | "execution_count": 5, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "# On affiche x\n", 88 | "list(x)" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 9, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "data": { 98 | "text/plain": [ 99 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]" 100 | ] 101 | }, 102 | "execution_count": 9, 103 | "metadata": {}, 104 | "output_type": "execute_result" 105 | } 106 | ], 107 | "source": [ 108 | "# On affiche vraiment le contenu de range() avec la fonction list\n", 109 | "list(x)" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "Bravo !\n", 117 | "Remarquez qu'il y a bien 20 *valeurs*, mais 20 ne fait pas partie de la liste. Comme pour l'indexation. \n", 118 | "Nous pouvons aussi modifier le pas, 1 par défaut, comme troisième argument:" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 11, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "data": { 128 | "text/plain": [ 129 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" 130 | ] 131 | }, 132 | "execution_count": 11, 133 | "metadata": {}, 134 | "output_type": "execute_result" 135 | } 136 | ], 137 | "source": [ 138 | "x = range(start,stop,2)\n", 139 | "# Afficher\n", 140 | "list(x)" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "Magnifique, dernier exemple avec une boucle for :" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 13, 153 | "metadata": {}, 154 | "outputs": [ 155 | { 156 | "name": "stdout", 157 | "output_type": "stream", 158 | "text": [ 159 | "0\n", 160 | "1\n", 161 | "2\n", 162 | "3\n", 163 | "4\n", 164 | "5\n", 165 | "6\n", 166 | "7\n", 167 | "8\n", 168 | "9\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "for num in range(10):\n", 174 | " print (num)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": { 180 | "collapsed": true 181 | }, 182 | "source": [ 183 | "Vous savez tout maintenant pour pouvoir utiliser range() en Python." 184 | ] 185 | } 186 | ], 187 | "metadata": { 188 | "anaconda-cloud": {}, 189 | "kernelspec": { 190 | "display_name": "Python 3", 191 | "language": "python", 192 | "name": "python3" 193 | }, 194 | "language_info": { 195 | "codemirror_mode": { 196 | "name": "ipython", 197 | "version": 3 198 | }, 199 | "file_extension": ".py", 200 | "mimetype": "text/x-python", 201 | "name": "python", 202 | "nbconvert_exporter": "python", 203 | "pygments_lexer": "ipython3", 204 | "version": "3.6.8" 205 | } 206 | }, 207 | "nbformat": 4, 208 | "nbformat_minor": 1 209 | } 210 | -------------------------------------------------------------------------------- /02-Python Déclarations/08-Listes en compréhension.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true 7 | }, 8 | "source": [ 9 | "# Listes en compréhension\n", 10 | "\n", 11 | "En plus des opérations séquencielles et des méthodes de liste, Python possède une fonctionnalité avancée appelée compréhension de liste.\n", 12 | "\n", 13 | "Les listes en compréhension nous permettent de construire des listes en utilisant une notation différente.\n", 14 | "C'est essentiellement une façon d'écrire une boucle incluse entre des crochets sur une seule ligne.\n", 15 | "\n", 16 | "Voici un exemple simple:\n", 17 | "\n", 18 | "## Exemple 1" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 1, 24 | "metadata": { 25 | "collapsed": true 26 | }, 27 | "outputs": [], 28 | "source": [ 29 | "# Extraire chaque lettre de la chaine\n", 30 | "liste = [x for x in 'exemple']" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 3, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "data": { 40 | "text/plain": [ 41 | "['e', 'x', 'e', 'm', 'p', 'l', 'e']" 42 | ] 43 | }, 44 | "execution_count": 3, 45 | "metadata": {}, 46 | "output_type": "execute_result" 47 | } 48 | ], 49 | "source": [ 50 | "# Affichage\n", 51 | "liste" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "C'était l'idée de base des listes de compréhension. Si vous êtes familiers de notation mathématique, vous devriez reconnaitre cet exemple : x^2 : x in { 0,1,2...10} \n", 59 | "\n", 60 | "Intéressons nous maintenant à d'autres exemples de listes de compréhension avec Python :\n", 61 | "## Exemple 2" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 4, 67 | "metadata": { 68 | "collapsed": true 69 | }, 70 | "outputs": [], 71 | "source": [ 72 | "# Liste crée à partir d'un range() de carrés\n", 73 | "lst = [x**2 for x in range(0,11)]" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 5, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "data": { 83 | "text/plain": [ 84 | "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]" 85 | ] 86 | }, 87 | "execution_count": 5, 88 | "metadata": {}, 89 | "output_type": "execute_result" 90 | } 91 | ], 92 | "source": [ 93 | "lst" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "## Exemple 3\n", 101 | "Voyons comment ajouter une instruction if" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 6, 107 | "metadata": { 108 | "collapsed": true 109 | }, 110 | "outputs": [], 111 | "source": [ 112 | "# Vérification de nombres pairs\n", 113 | "lst = [x for x in range(11) if x % 2 == 0]" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 7, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/plain": [ 124 | "[0, 2, 4, 6, 8, 10]" 125 | ] 126 | }, 127 | "execution_count": 7, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "lst" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": {}, 139 | "source": [ 140 | "## Exemple 4\n", 141 | "On peut faire aussi des calculs plus compliqués :" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 9, 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "data": { 151 | "text/plain": [ 152 | "[32.0, 50.0, 68.18, 94.1]" 153 | ] 154 | }, 155 | "execution_count": 9, 156 | "metadata": {}, 157 | "output_type": "execute_result" 158 | } 159 | ], 160 | "source": [ 161 | "# Conversion de Celsius en Fahrenheit\n", 162 | "celsius = [0,10,20.1,34.5]\n", 163 | "\n", 164 | "fahrenheit = [ ((float(9)/5)*temp + 32) for temp in celsius ]\n", 165 | "\n", 166 | "fahrenheit" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "## Exemple 5\n", 174 | "On peut également imbriquer des listes de compréhension, par exemple :" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 10, 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "data": { 184 | "text/plain": [ 185 | "[0, 1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 10000]" 186 | ] 187 | }, 188 | "execution_count": 10, 189 | "metadata": {}, 190 | "output_type": "execute_result" 191 | } 192 | ], 193 | "source": [ 194 | "lst = [ x**2 for x in [x**2 for x in range(11)]]\n", 195 | "lst" 196 | ] 197 | }, 198 | { 199 | "cell_type": "markdown", 200 | "metadata": {}, 201 | "source": [ 202 | "Plus loin dans le cours, nous verrons la notion de générateurs.\n", 203 | "Vous devriez maintenant être à l'aise pour lire et écrire des listes de compréhensions simples." 204 | ] 205 | } 206 | ], 207 | "metadata": { 208 | "anaconda-cloud": {}, 209 | "kernelspec": { 210 | "display_name": "Python 3", 211 | "language": "python", 212 | "name": "python3" 213 | }, 214 | "language_info": { 215 | "codemirror_mode": { 216 | "name": "ipython", 217 | "version": 3 218 | }, 219 | "file_extension": ".py", 220 | "mimetype": "text/x-python", 221 | "name": "python", 222 | "nbconvert_exporter": "python", 223 | "pygments_lexer": "ipython3", 224 | "version": "3.6.8" 225 | } 226 | }, 227 | "nbformat": 4, 228 | "nbformat_minor": 1 229 | } 230 | -------------------------------------------------------------------------------- /02-Python Déclarations/Contrôle des connaissances.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true 7 | }, 8 | "source": [ 9 | "# Contrôle des connaissances\n", 10 | "\n", 11 | "Voyons un peu ce que vous avez appris !" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "_____\n", 19 | "**Utilisez les instructions for, split(), et if pour créer un code qui va n'afficher que les mots qui commencent par 'c' dans cette phrase :**" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 3, 25 | "metadata": { 26 | "collapsed": true 27 | }, 28 | "outputs": [], 29 | "source": [ 30 | "st = \"Cet exercice consiste à afficher uniquement les mots commencent par la lettre c\"" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 1, 36 | "metadata": { 37 | "collapsed": false 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "# Votre code" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "______\n", 49 | "**Utilisez range() pour afficher les nombres pairs de 0 à 10.**" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 2, 55 | "metadata": { 56 | "collapsed": false 57 | }, 58 | "outputs": [], 59 | "source": [ 60 | "# Votre code" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "___\n", 68 | "**Utilisez la compréhension de liste pour créer la liste des nombres divisibles par 3 compris entre 1 et 50.**" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 3, 74 | "metadata": { 75 | "collapsed": false 76 | }, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "[]" 82 | ] 83 | }, 84 | "execution_count": 3, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "# Votre code\n", 91 | "[]" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "_____\n", 99 | "**Dans la chaine suivante, vérifiez le nombre de lettre de chaque mot et si celui-ci est pair, affichez le mot aveec \"pair !\"**" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 6, 105 | "metadata": { 106 | "collapsed": true 107 | }, 108 | "outputs": [], 109 | "source": [ 110 | "st = 'Affichez chaque mot de cette phrase dont le nombre de lettres est pair'" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 4, 116 | "metadata": { 117 | "collapsed": true 118 | }, 119 | "outputs": [], 120 | "source": [ 121 | "# Votre code" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "**Écrire un programme qui affiche les nombres entiers de 1 à 100. Pour les multiples de trois afficher \"Fizz\" à la place du nombre et pour les multiples de cinq afficher \"Buzz\". Pour les nombres qui sont à la fois des multiples de trois et de cinq afficher \"FizzBuzz\". **" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": null, 134 | "metadata": { 135 | "collapsed": false 136 | }, 137 | "outputs": [], 138 | "source": [ 139 | "# Votre code" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": {}, 145 | "source": [ 146 | "____\n", 147 | "**Utilisez la compréhension de liste pour créer la liste des cinq premières lettres de chaque mot dans la chaine ci dessous :**" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 1, 153 | "metadata": { 154 | "collapsed": true 155 | }, 156 | "outputs": [], 157 | "source": [ 158 | "st = \"Création d'une liste des cinq premières lettres de chaque mot de cette chaine de caractères\"" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 2, 164 | "metadata": { 165 | "collapsed": true 166 | }, 167 | "outputs": [], 168 | "source": [ 169 | "# Votre code" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "### Bravo !" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "metadata": { 183 | "collapsed": true 184 | }, 185 | "outputs": [], 186 | "source": [] 187 | } 188 | ], 189 | "metadata": { 190 | "anaconda-cloud": {}, 191 | "kernelspec": { 192 | "display_name": "Python [default]", 193 | "language": "python", 194 | "name": "python3" 195 | }, 196 | "language_info": { 197 | "codemirror_mode": { 198 | "name": "ipython", 199 | "version": 3 200 | }, 201 | "file_extension": ".py", 202 | "mimetype": "text/x-python", 203 | "name": "python", 204 | "nbconvert_exporter": "python", 205 | "pygments_lexer": "ipython3", 206 | "version": "3.5.2" 207 | } 208 | }, 209 | "nbformat": 4, 210 | "nbformat_minor": 0 211 | } 212 | -------------------------------------------------------------------------------- /03-Méthodes et Fonctions/02-Les méthodes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Les méthodes\n", 8 | "\n", 9 | "Nous avons déjà vu quelques exemples de méthodes avec la leçon sur les objets et les structures de données Python. De façon très simplifiée, les méthodes sont des fonctions construites à l'intérieur des objets. Un peu plus tard dans le cours, nous apprendrons à créer nos propres objets et méthodes en utilisation la Programmation Orientée Objet (POO) et les classes.\n", 10 | "\n", 11 | "Les méthodes exécutent des actions spécifiques sur l'objet lui-même et peuvent également prendre des paramètres, tout comme une fonction. Cette leçon est une brève introduction aux méthodes et vous permettra de commencer réfléchir à la conception ce sur quoi nous reviendrons quand nous arriverons à la partie POO du cours.\n", 12 | "\n", 13 | "Les méthodes sont de la forme :\n", 14 | "\n", 15 | " objet.méthode(parm1,parm2,etc...)\n", 16 | "\n", 17 | "Nous verrons plus tard que certaines méthodes peuvent avoir un paramètre 'self' pour faire référence à l'objet lui-même. Nous verrons cela avec la partie POO.\n", 18 | "\n", 19 | "Faisons un rapide tour d'horizon des méthodes que l'on peut retrouver avec un objet liste :" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 2, 25 | "metadata": { 26 | "collapsed": true 27 | }, 28 | "outputs": [], 29 | "source": [ 30 | "# Création d'une liste simple\n", 31 | "l = [1,2,3,4,5]" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "Heureusement, avec iPython et les Notebooks Jupyter nous pouvons retrouver rapidement toutes les méthodes applicables à un objet au moyen de la touche tabulation. Il suffit pour cela de taper le nom de l'objet dans une cellule, suivit d'un point et ensuite la touche tabulation.\n", 39 | "\n", 40 | "Les méthodes pour une liste sont les suivantes :\n", 41 | "\n", 42 | "* append\n", 43 | "* count\n", 44 | "* extend\n", 45 | "* insert\n", 46 | "* pop\n", 47 | "* remove\n", 48 | "* reverse\n", 49 | "* sort\n", 50 | "\n", 51 | "Essayons en quelques unes :" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "append() nous permet d'jouter des éléments à la fin d'une liste :" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 3, 64 | "metadata": { 65 | "collapsed": true 66 | }, 67 | "outputs": [], 68 | "source": [ 69 | "l.append(6)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 4, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "data": { 79 | "text/plain": [ 80 | "[1, 2, 3, 4, 5, 6]" 81 | ] 82 | }, 83 | "execution_count": 4, 84 | "metadata": {}, 85 | "output_type": "execute_result" 86 | } 87 | ], 88 | "source": [ 89 | "l" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "Bravo ! Et count() alors ? La méthode count() va dénombrer le nombre d'occurences d'un élément dans une liste." 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 5, 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "data": { 106 | "text/plain": [ 107 | "1" 108 | ] 109 | }, 110 | "execution_count": 5, 111 | "metadata": {}, 112 | "output_type": "execute_result" 113 | } 114 | ], 115 | "source": [ 116 | "# Vérifie combien de fois 2 apparait dans la liste\n", 117 | "l.count(2)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "Il est également possible d'utiliser majuscule et tabulation dans un Notebook Jupyter pour obtenir de l'aide à propos d'une méthode. Avec Python plus généralement, il faudra utiliser la fonction help() :" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 7, 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "name": "stdout", 134 | "output_type": "stream", 135 | "text": [ 136 | "Help on built-in function count:\n", 137 | "\n", 138 | "count(...) method of builtins.list instance\n", 139 | " L.count(value) -> integer -- return number of occurrences of value\n", 140 | "\n" 141 | ] 142 | } 143 | ], 144 | "source": [ 145 | "help(l.count)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "metadata": {}, 151 | "source": [ 152 | "N'hésitez pas à test les autres méthodes d'un objet liste. Plus tard dans cette section le controle de connaissances vous demandera d'utiliser help et Google pour retrouver les méthodes de différents objets !" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "Bravo !\n", 160 | "Avec cette leçon vous devriez maintenant être à l'aise pour appeler les méthodes d'objets Python !" 161 | ] 162 | } 163 | ], 164 | "metadata": { 165 | "anaconda-cloud": {}, 166 | "kernelspec": { 167 | "display_name": "Python 3", 168 | "language": "python", 169 | "name": "python3" 170 | }, 171 | "language_info": { 172 | "codemirror_mode": { 173 | "name": "ipython", 174 | "version": 3 175 | }, 176 | "file_extension": ".py", 177 | "mimetype": "text/x-python", 178 | "name": "python", 179 | "nbconvert_exporter": "python", 180 | "pygments_lexer": "ipython3", 181 | "version": "3.6.8" 182 | } 183 | }, 184 | "nbformat": 4, 185 | "nbformat_minor": 1 186 | } 187 | -------------------------------------------------------------------------------- /03-Méthodes et Fonctions/Controle de connaissances sur les fonctions et les méthodes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Controle de connaissances sur les fonctions et les méthodes\n", 8 | "\n", 9 | "Répondez aux questions suivantes :\n", 10 | "____\n", 11 | "**Ecrire une fonction qui renvoie le volume d'une sphère en fonction de son rayon**" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": { 18 | "collapsed": true 19 | }, 20 | "outputs": [], 21 | "source": [ 22 | "def vol(rayon):\n", 23 | " pass" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "**Ecrire une fonction qui vérifie qu'un nombre est situé dans un intervalle donné (bornes incluses)**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 7, 36 | "metadata": { 37 | "collapsed": true 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "def verif_intervalle(num,bas,haut):\n", 42 | " pass" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "Réponse sous forme d'un booléen :" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 8, 55 | "metadata": { 56 | "collapsed": true 57 | }, 58 | "outputs": [], 59 | "source": [ 60 | "def bool_intervalle(num,bas,haut):\n", 61 | " pass" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 9, 67 | "metadata": { 68 | "collapsed": false 69 | }, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "True" 75 | ] 76 | }, 77 | "execution_count": 9, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "bool_intervalle(3,1,10)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "____\n", 91 | "** Écrivez une fonction Python qui calcule le nombre de lettres majuscules et minuscules dans une chaine. **\n", 92 | "\n", 93 | " Exemple de chaine : \"Bonjour Mr Martin, comment allez vous en cette belle journée de mardi ?\"\n", 94 | " Réponse souhaitée :\n", 95 | " Nombre de majuscules : 3\n", 96 | " Nombre de minuscules : 54\n", 97 | " \n", 98 | "Si vous vous sentez en forme, vous pouvez allez voir ce qu'il y a dans le module Collections pour résoudre ce problème !" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 11, 104 | "metadata": { 105 | "collapsed": true 106 | }, 107 | "outputs": [], 108 | "source": [ 109 | "def maj_min(s):\n", 110 | " pass" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "____\n", 118 | "**Ecrire une fonction Python qui prend une liste en entrée et retourne une nouvelle liste avec les éléments uniques de la première liste.**\n", 119 | "\n", 120 | " Exemple de liste : [1,1,1,1,2,2,3,3,3,3,4,5]\n", 121 | " Liste unique : [1, 2, 3, 4, 5]" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 2, 127 | "metadata": { 128 | "collapsed": true 129 | }, 130 | "outputs": [], 131 | "source": [ 132 | "def liste_unique(l):\n", 133 | " pass" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 4, 139 | "metadata": { 140 | "collapsed": false 141 | }, 142 | "outputs": [], 143 | "source": [ 144 | "liste_unique([1,1,1,1,2,2,3,3,3,3,4,5])" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "____\n", 152 | "**Ecrire une fonction Python qui multiplie tous les nombres de la liste.**\n", 153 | "\n", 154 | " Exemple de liste : [1, 2, 3, -4]\n", 155 | " Sortie attendue : -24" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 17, 161 | "metadata": { 162 | "collapsed": true 163 | }, 164 | "outputs": [], 165 | "source": [ 166 | "def multiplie(nombre): \n", 167 | " pass" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 18, 173 | "metadata": { 174 | "collapsed": false 175 | }, 176 | "outputs": [ 177 | { 178 | "data": { 179 | "text/plain": [ 180 | "-24" 181 | ] 182 | }, 183 | "execution_count": 18, 184 | "metadata": {}, 185 | "output_type": "execute_result" 186 | } 187 | ], 188 | "source": [ 189 | "multiplie([1,2,3,-4])" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "____\n", 197 | "**Ecrire une fonction Python qui vérifie si une chaîne passée est un palindrome.**\n", 198 | "\n", 199 | "Note: Un palindrome est un mot, une phrase ou une séquence qui se lit vers l'arrière et vers l'avant, par exemple, kayak ou rêver." 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 5, 205 | "metadata": { 206 | "collapsed": true 207 | }, 208 | "outputs": [], 209 | "source": [ 210 | "def palindrome(s):\n", 211 | " pass" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 6, 217 | "metadata": { 218 | "collapsed": false 219 | }, 220 | "outputs": [], 221 | "source": [ 222 | "palindrome('kayak')" 223 | ] 224 | }, 225 | { 226 | "cell_type": "markdown", 227 | "metadata": {}, 228 | "source": [ 229 | "____\n", 230 | "**Difficile**:\n", 231 | "\n", 232 | "Ecrire une fonction Python pour vérifier si une chaîne est un pangramme.\n", 233 | "\n", 234 | " Note : Un pangramme est une phrase contenant chaque lettre de l'alphabet au moins une fois.\n", 235 | " Par exemple : \"Buvez de ce whisky que le patron juge fameux\"\n", 236 | "\n", 237 | "Indice : Regardez le module String" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 7, 243 | "metadata": { 244 | "collapsed": true 245 | }, 246 | "outputs": [], 247 | "source": [ 248 | "import string\n", 249 | "\n", 250 | "def est_un_pangramme(str1, alphabet=string.ascii_lowercase): \n", 251 | " pass" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 8, 257 | "metadata": { 258 | "collapsed": false 259 | }, 260 | "outputs": [], 261 | "source": [ 262 | "est_un_pangramme(\"Buvez de ce whisky que le patron juge fameux\")" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 9, 268 | "metadata": { 269 | "collapsed": false 270 | }, 271 | "outputs": [ 272 | { 273 | "data": { 274 | "text/plain": [ 275 | "'abcdefghijklmnopqrstuvwxyz'" 276 | ] 277 | }, 278 | "execution_count": 9, 279 | "metadata": {}, 280 | "output_type": "execute_result" 281 | } 282 | ], 283 | "source": [ 284 | "string.ascii_lowercase" 285 | ] 286 | }, 287 | { 288 | "cell_type": "markdown", 289 | "metadata": { 290 | "collapsed": true 291 | }, 292 | "source": [ 293 | "#### **Bravo !**" 294 | ] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": null, 299 | "metadata": { 300 | "collapsed": true 301 | }, 302 | "outputs": [], 303 | "source": [] 304 | } 305 | ], 306 | "metadata": { 307 | "anaconda-cloud": {}, 308 | "kernelspec": { 309 | "display_name": "Python [default]", 310 | "language": "python", 311 | "name": "python3" 312 | }, 313 | "language_info": { 314 | "codemirror_mode": { 315 | "name": "ipython", 316 | "version": 3 317 | }, 318 | "file_extension": ".py", 319 | "mimetype": "text/x-python", 320 | "name": "python", 321 | "nbconvert_exporter": "python", 322 | "pygments_lexer": "ipython3", 323 | "version": "3.5.2" 324 | } 325 | }, 326 | "nbformat": 4, 327 | "nbformat_minor": 0 328 | } 329 | -------------------------------------------------------------------------------- /04-Premier Projet/1 - Présentation du premier project.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Lancement du premier projet !\n", 8 | "## Présentation du projet\n", 9 | "\n", 10 | "Vous avez déjà beaucoup appris et vous êtes prêt pour travailler sur un vrai projet.\n", 11 | "\n", 12 | "Votre tâche : Créer un jeu de Morpion. Vous pouvez utiliser l'environnement de développement (IDE) que vous voulez. \n", 13 | "\n", 14 | "Voici les exigences :\n", 15 | "\n", 16 | "* c'est un jeu pour 2 personnes qui utilisent le même ordinateur.\n", 17 | "* le tableau de jeu est affiché chaque fois qu'un joueur place une marque\n", 18 | "* Vous devez demander au joueur la position de son mouvement et ensuite placer la marque sur le tableau\n", 19 | "\n", 20 | "Vous pouvez utiliser Google pour vous aider (mais ne cherchez pas \"Morpion en Python\", sinon vous n'apprendrez pas grand chose !). Gardez présent à l'esprit que ce projet peut dure de quelques heures à plusieurs jours.\n", 21 | "\n", 22 | "Il y a 3 bloc-notes Jupyter qui se rapportent à ce travail :\n", 23 | "\n", 24 | "* Ce bloc-note avec la présentation du travail à faire\n", 25 | "* Un bloc-note \"Feuille de route\" qui propose les étapes à suivre pour coder le jeu\n", 26 | "* Un bloc-note \"Solution\" avec les explications et le code du jeu\n", 27 | "\n", 28 | "Je vous encourage à démarrer le projet seul et sans retourner dans les bloc-notes Jupyter. Si vous êtes bloqué, consultez d'abord la prochaine leçon qui est un document comportant de nombreux conseils et les étapes utiles. Si vous êtes toujours coincé après cela, consultez la feuille de route, qui divise le projet en étapes simples à résoudre. Toujours bloqué ? Ensuite, vous pourrez consulter la vidéo de la feuille de route pour plus d'aide sur la manière de venir à bout de ce projet !" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "Il y a des parties pour lesquelles vous pouvez avoir à batailler... et c'est bien !\n", 36 | "J'ai confiance dans le fait que vous avez tous les outils et les connaissances pour réaliser ce projet si vous avez bien suivi toutes les leçons jusqu'ici . Rappelez-vous, vous pouvez consulter toute la documentation dont vous avez besoin, prenez votre temps, faites un peu de recherches, et n'oubliez surtout pas :\n", 37 | "\n", 38 | "## AMUSEZ VOUS BIEN !" 39 | ] 40 | } 41 | ], 42 | "metadata": { 43 | "anaconda-cloud": {}, 44 | "kernelspec": { 45 | "display_name": "Python [default]", 46 | "language": "python", 47 | "name": "python3" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 3 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython3", 59 | "version": "3.5.2" 60 | } 61 | }, 62 | "nbformat": 4, 63 | "nbformat_minor": 0 64 | } 65 | -------------------------------------------------------------------------------- /04-Premier Projet/2 - Premier Projet d'étape - Feuille de route détaillée.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Premier Projet d'étape : Feuille de route\n", 8 | "\n", 9 | "Vous trouverez ci dessous les étapes à suivre pour créer le jeu de Morpion de votre projet d'étape." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "**1ère étape : Ecrire une fonction pour afficher le tableau de jeu. Configurer votre tableau comme une liste, où chaque index 1-9 correspond à un nombre sur un clavier, de sorte que vous obtenez un terrain de 3 par 3.**" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 2, 22 | "metadata": { 23 | "collapsed": true 24 | }, 25 | "outputs": [], 26 | "source": [ 27 | "from IPython.display import clear_output\n", 28 | "def affiche_tableau(tableau):\n", 29 | " pass" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "**2ème étape : Ecrire une fonction qui demande au joueur quelle marque «X» ou «O» il veut utiliser et lui assigner. Pensez à utiliser une boucle *while* pour demander une réponse au joueur jusqu'à obtenir une réponse correcte.**" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 3, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "def action_joueur():\n", 48 | " pass" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "**3ème étape : Ecrire une fonction qui manipule, dans l'objet tableau (list), une marque ('X' ou 'O') et la position désirée (numéro 1-9) et l'affecte au tableau.**" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 4, 61 | "metadata": { 62 | "collapsed": true 63 | }, 64 | "outputs": [], 65 | "source": [ 66 | "def placer_marque(tableau, marque, position):\n", 67 | " pass" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "**4ème étape : Ecrire une fonction qui prend un tableau et une marque (X ou O), puis vérifie si cette marque a gagné. **" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 1, 80 | "metadata": { 81 | "collapsed": true 82 | }, 83 | "outputs": [], 84 | "source": [ 85 | "def vérifie_gagnant(tableau, marque):\n", 86 | " pass" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": {}, 92 | "source": [ 93 | "**5ème étape : Ecrire une fonction qui utilise le module random pour décider au hasard quel joueur va jouer en premier. Vous devriez chercher du côté de random.randint(). La fonction retourne une chaîne qui indique le joueur qui joue le premier.**" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 91, 99 | "metadata": { 100 | "collapsed": true 101 | }, 102 | "outputs": [], 103 | "source": [ 104 | "import random\n", 105 | "def choix_premier():\n", 106 | " pass" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "**6ème étape :Ecrire une fonction qui renvoie un booléen indiquant si un espace sur la carte est disponible.**" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 92, 119 | "metadata": { 120 | "collapsed": true 121 | }, 122 | "outputs": [], 123 | "source": [ 124 | "def vérifie_position(tableau, position):\n", 125 | " pass" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "**7ème étape : Ecrire une fonction qui vérifie si le tableau est plein et renvoie une valeur booléenne. Vrai si plein, Faux autrement.**" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 5, 138 | "metadata": { 139 | "collapsed": true 140 | }, 141 | "outputs": [], 142 | "source": [ 143 | "def vérifie_tableau_complet(tableau):\n", 144 | " pass" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "**8ème étape : Ecrire une fonction qui demande au joueur la position où il veut placer sa marque (comme un nombre 1-9), puis utilise la fonction de l'étape 6 pour vérifier si sa position libre. Si c'est le cas, retourne la position pour pouvoir l'utiliser. **" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 94, 157 | "metadata": { 158 | "collapsed": true 159 | }, 160 | "outputs": [], 161 | "source": [ 162 | "def choix_du_joueur(tableau):\n", 163 | " pass" 164 | ] 165 | }, 166 | { 167 | "cell_type": "markdown", 168 | "metadata": {}, 169 | "source": [ 170 | "**9ème étape : Ecrire une fonction qui demande au joueur s'il veut jouer de nouveau et retourne un booléen Vrai si oui.**" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 1, 176 | "metadata": { 177 | "collapsed": true 178 | }, 179 | "outputs": [], 180 | "source": [ 181 | "def rejouer():\n", 182 | " pass" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": { 188 | "collapsed": true 189 | }, 190 | "source": [ 191 | "**10ème étape : Voici la partie difficile ! Utilisez boucles while et les fonctions que vous venez d'écrire pour donner vie au jeu!**" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": 2, 197 | "metadata": { 198 | "collapsed": false 199 | }, 200 | "outputs": [ 201 | { 202 | "name": "stdout", 203 | "output_type": "stream", 204 | "text": [ 205 | "Bienvenue dans le jeu de Morpion !\n" 206 | ] 207 | } 208 | ], 209 | "source": [ 210 | "print('Bienvenue dans le jeu de Morpion !')\n", 211 | "\n", 212 | "#while True:\n", 213 | " # Préparer le tableau\n", 214 | " #pass\n", 215 | "\n", 216 | " #while jeu_en_cours:\n", 217 | " # Tour du joueur 1\n", 218 | " \n", 219 | " \n", 220 | " # Tour du joueur 2\n", 221 | " \n", 222 | " #pass\n", 223 | "\n", 224 | " #if not rejouer():\n", 225 | " #break" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": { 231 | "collapsed": true 232 | }, 233 | "source": [ 234 | "## Bravo !" 235 | ] 236 | } 237 | ], 238 | "metadata": { 239 | "anaconda-cloud": {}, 240 | "kernelspec": { 241 | "display_name": "Python 3", 242 | "language": "python", 243 | "name": "python3" 244 | }, 245 | "language_info": { 246 | "codemirror_mode": { 247 | "name": "ipython", 248 | "version": 3 249 | }, 250 | "file_extension": ".py", 251 | "mimetype": "text/x-python", 252 | "name": "python", 253 | "nbconvert_exporter": "python", 254 | "pygments_lexer": "ipython3", 255 | "version": "3.6.0" 256 | } 257 | }, 258 | "nbformat": 4, 259 | "nbformat_minor": 0 260 | } 261 | -------------------------------------------------------------------------------- /05-Programmation Orientée Objet/Programmation Orientée Objet - Contrôle de connaissances - Solution.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Programmation Orientée Objet\n", 8 | "## Solution du contrôle de connaissances\n", 9 | "\n", 10 | "#### 1er problème\n", 11 | "\n", 12 | "Complétez les méthodes de la classe Ligne pour accepter en paramètre les coordonnées comme une paire de tuples et renvoyer la pente et la distance à la ligne." 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 1, 18 | "metadata": { 19 | "collapsed": true 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "class Ligne(object):\n", 24 | " \n", 25 | " def __init__(self,coor1,coor2):\n", 26 | " self.coor1 = coor1\n", 27 | " self.coor2 = coor2\n", 28 | " \n", 29 | " def distance(self):\n", 30 | " x1,y1 = self.coor1\n", 31 | " x2,y2 = self.coor2\n", 32 | " return ( (x2-x1)**2 + (y2-y1)**2 )**0.5\n", 33 | " \n", 34 | " def pente(self):\n", 35 | " x1,y1 = self.coor1\n", 36 | " x2,y2 = self.coor2\n", 37 | " return float((y2-y1))/(x2-x1)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 9, 43 | "metadata": { 44 | "collapsed": true 45 | }, 46 | "outputs": [], 47 | "source": [ 48 | "coordonnées1 = (3,2)\n", 49 | "coordonnées2 = (8,10)\n", 50 | "\n", 51 | "li = Ligne(coordonnées1,coordonnées2)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 10, 57 | "metadata": { 58 | "collapsed": false 59 | }, 60 | "outputs": [ 61 | { 62 | "data": { 63 | "text/plain": [ 64 | "9.433981132056603" 65 | ] 66 | }, 67 | "execution_count": 10, 68 | "metadata": {}, 69 | "output_type": "execute_result" 70 | } 71 | ], 72 | "source": [ 73 | "li.distance()" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 11, 79 | "metadata": { 80 | "collapsed": false 81 | }, 82 | "outputs": [ 83 | { 84 | "data": { 85 | "text/plain": [ 86 | "1.6" 87 | ] 88 | }, 89 | "execution_count": 11, 90 | "metadata": {}, 91 | "output_type": "execute_result" 92 | } 93 | ], 94 | "source": [ 95 | "li.pente()" 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": {}, 101 | "source": [ 102 | "________\n", 103 | "#### 2ème problème" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "Complétez la classe" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 12, 116 | "metadata": { 117 | "collapsed": false 118 | }, 119 | "outputs": [], 120 | "source": [ 121 | "class Cylindre(object):\n", 122 | " \n", 123 | " def __init__(self,hauteur=1,rayon=1):\n", 124 | " self.hauteur = hauteur\n", 125 | " self.rayon = rayon\n", 126 | " \n", 127 | " def volume(self):\n", 128 | " return self.hauteur * (3.14)* (self.rayon)**2\n", 129 | " \n", 130 | " def surface(self):\n", 131 | " dessus = (3.14)* (self.rayon)**2\n", 132 | " return 2*dessus + 2*3.14*self.rayon*self.hauteur" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 13, 138 | "metadata": { 139 | "collapsed": true 140 | }, 141 | "outputs": [], 142 | "source": [ 143 | "c = Cylindre(2,3)" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 14, 149 | "metadata": { 150 | "collapsed": false 151 | }, 152 | "outputs": [ 153 | { 154 | "data": { 155 | "text/plain": [ 156 | "56.52" 157 | ] 158 | }, 159 | "execution_count": 14, 160 | "metadata": {}, 161 | "output_type": "execute_result" 162 | } 163 | ], 164 | "source": [ 165 | "c.volume()" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 15, 171 | "metadata": { 172 | "collapsed": false 173 | }, 174 | "outputs": [ 175 | { 176 | "data": { 177 | "text/plain": [ 178 | "94.2" 179 | ] 180 | }, 181 | "execution_count": 15, 182 | "metadata": {}, 183 | "output_type": "execute_result" 184 | } 185 | ], 186 | "source": [ 187 | "c.surface()" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": { 194 | "collapsed": true 195 | }, 196 | "outputs": [], 197 | "source": [] 198 | } 199 | ], 200 | "metadata": { 201 | "anaconda-cloud": {}, 202 | "kernelspec": { 203 | <<<<<<< HEAD:Partie_05_Programmation_Orientée_Objet/Programmation Orientée Objet - Contrôle de connaissances - Solution.ipynb 204 | "display_name": "Python [default]", 205 | ======= 206 | "display_name": "Python 3", 207 | >>>>>>> marc:Partie_05_Programmation_Orientée_Objet/Programmation Orientée Objet - Contrôle de connaissances - Solution.ipynb 208 | "language": "python", 209 | "name": "python3" 210 | }, 211 | "language_info": { 212 | "codemirror_mode": { 213 | "name": "ipython", 214 | "version": 3 215 | }, 216 | "file_extension": ".py", 217 | "mimetype": "text/x-python", 218 | "name": "python", 219 | "nbconvert_exporter": "python", 220 | "pygments_lexer": "ipython3", 221 | <<<<<<< HEAD:Partie_05_Programmation_Orientée_Objet/Programmation Orientée Objet - Contrôle de connaissances - Solution.ipynb 222 | "version": "3.5.2" 223 | ======= 224 | "version": "3.6.0" 225 | >>>>>>> marc:Partie_05_Programmation_Orientée_Objet/Programmation Orientée Objet - Contrôle de connaissances - Solution.ipynb 226 | } 227 | }, 228 | "nbformat": 4, 229 | "nbformat_minor": 0 230 | } 231 | -------------------------------------------------------------------------------- /05-Programmation Orientée Objet/Programmation Orientée Objet - Contrôle de connaissances.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Programmation Orientée Objet\n", 8 | "## Votre mission et contrôle de connaissances\n", 9 | "\n", 10 | "#### 1er problème\n", 11 | "\n", 12 | "Complétez les méthodes de la classe Ligne pour accepter en paramètre les coordonnées comme une paire de tuples et renvoyer la pente et la distance à la ligne." 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 2, 18 | "metadata": { 19 | "collapsed": true 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "class Ligne(object):\n", 24 | " \n", 25 | " def __init__(self,coor1,coor2):\n", 26 | " pass\n", 27 | " \n", 28 | " def distance(self):\n", 29 | " pass\n", 30 | " \n", 31 | " def pente(self):\n", 32 | " pass" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": { 39 | "collapsed": false 40 | }, 41 | "outputs": [], 42 | "source": [ 43 | "# EXEMPLE DE SORTIE\n", 44 | "\n", 45 | "coordonnées1 = (3,2)\n", 46 | "coordonnées2 = (8,10)\n", 47 | "\n", 48 | "li = Ligne(coordonnées1,coordonnées2)" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 4, 54 | "metadata": { 55 | "collapsed": false 56 | }, 57 | "outputs": [], 58 | "source": [ 59 | "li.distance()" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 5, 65 | "metadata": { 66 | "collapsed": false 67 | }, 68 | "outputs": [], 69 | "source": [ 70 | "li.pente()" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "________\n", 78 | "#### 2ème problème" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "Complétez la classe" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 6, 91 | "metadata": { 92 | "collapsed": false 93 | }, 94 | "outputs": [], 95 | "source": [ 96 | "class Cylindre(object):\n", 97 | " \n", 98 | " def __init__(self,hauteur=1,rayon=1):\n", 99 | " pass\n", 100 | " \n", 101 | " def volume(self):\n", 102 | " pass\n", 103 | " \n", 104 | " def surface(self):\n", 105 | " pass" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 7, 111 | "metadata": { 112 | "collapsed": true 113 | }, 114 | "outputs": [], 115 | "source": [ 116 | "# EXEMPLE DE SORTIE\n", 117 | "c = Cylindre(2,3)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 8, 123 | "metadata": { 124 | "collapsed": false 125 | }, 126 | "outputs": [], 127 | "source": [ 128 | "c.volume()" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 9, 134 | "metadata": { 135 | "collapsed": false 136 | }, 137 | "outputs": [], 138 | "source": [ 139 | "c.surface()" 140 | ] 141 | } 142 | ], 143 | "metadata": { 144 | "anaconda-cloud": {}, 145 | "kernelspec": { 146 | "display_name": "Python [default]", 147 | "language": "python", 148 | "name": "python3" 149 | }, 150 | "language_info": { 151 | "codemirror_mode": { 152 | "name": "ipython", 153 | "version": 3 154 | }, 155 | "file_extension": ".py", 156 | "mimetype": "text/x-python", 157 | "name": "python", 158 | "nbconvert_exporter": "python", 159 | "pygments_lexer": "ipython3", 160 | "version": "3.5.2" 161 | } 162 | }, 163 | "nbformat": 4, 164 | "nbformat_minor": 0 165 | } 166 | -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/SubPackage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/SubPackage/__init__.py -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/SubPackage/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/SubPackage/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/SubPackage/__pycache__/mysubscript.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/SubPackage/__pycache__/mysubscript.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/SubPackage/mysubscript.py: -------------------------------------------------------------------------------- 1 | def sub_report(): 2 | print("Hey Im a function inside mysubscript") -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/__init__.py -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/__pycache__/some_main_script.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/__pycache__/some_main_script.cpython-36.pyc -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/MyMainPackage/some_main_script.py: -------------------------------------------------------------------------------- 1 | def report_main(): 2 | print("Hey I am in some_main_script in main package.") -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/mymodule.py: -------------------------------------------------------------------------------- 1 | def my_func(): 2 | print("Hey I am in mymodule.py") -------------------------------------------------------------------------------- /06-Modules et Paquets/00-Modules_and_Packages/myprogram.py: -------------------------------------------------------------------------------- 1 | from MyMainPackage.some_main_script import report_main 2 | from MyMainPackage.SubPackage import mysubscript 3 | 4 | report_main() 5 | 6 | mysubscript.sub_report() 7 | -------------------------------------------------------------------------------- /06-Modules et Paquets/01-Name_and_Main/Explanation.txt: -------------------------------------------------------------------------------- 1 | Sometimes when you are importing from a module, you would like to know whether 2 | a modules function is being used as an import, or if you are using the original 3 | .py file of that module. In this case we can use the: 4 | 5 | if __name__ == "__main__": 6 | 7 | line to determine this. For example: 8 | 9 | When your script is run by passing it as a command to the Python interpreter: 10 | 11 | python myscript.py 12 | 13 | all of the code that is at indentation level 0 gets executed. Functions and 14 | classes that are defined are, well, defined, but none of their code gets ran. 15 | Unlike other languages, there's no main() function that gets run automatically 16 | - the main() function is implicitly all the code at the top level. 17 | 18 | In this case, the top-level code is an if block. __name__ is a built-in variable 19 | which evaluate to the name of the current module. However, if a module is being 20 | run directly (as in myscript.py above), then __name__ instead is set to the 21 | string "__main__". Thus, you can test whether your script is being run directly 22 | or being imported by something else by testing 23 | 24 | if __name__ == "__main__": 25 | ... 26 | 27 | If that code is being imported into another module, the various function and 28 | class definitions will be imported, but the main() code won't get run. As a 29 | basic example, consider the following two scripts: 30 | 31 | # file one.py 32 | def func(): 33 | print("func() in one.py") 34 | 35 | print("top-level in one.py") 36 | 37 | if __name__ == "__main__": 38 | print("one.py is being run directly") 39 | else: 40 | print("one.py is being imported into another module") 41 | 42 | and then: 43 | 44 | # file two.py 45 | import one 46 | 47 | print("top-level in two.py") 48 | one.func() 49 | 50 | if __name__ == "__main__": 51 | print("two.py is being run directly") 52 | else: 53 | print("two.py is being imported into another module") 54 | 55 | Now, if you invoke the interpreter as 56 | 57 | python one.py 58 | 59 | The output will be 60 | 61 | top-level in one.py 62 | 63 | one.py is being run directly 64 | If you run two.py instead: 65 | 66 | python two.py 67 | 68 | You get 69 | 70 | top-level in one.py 71 | one.py is being imported into another module 72 | top-level in two.py 73 | func() in one.py 74 | two.py is being run directly 75 | 76 | Thus, when module one gets loaded, its __name__ equals "one" instead of __main__. 77 | -------------------------------------------------------------------------------- /06-Modules et Paquets/01-Name_and_Main/one.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print("func() ran in one.py") 3 | 4 | print("top-level print inside of one.py") 5 | 6 | if __name__ == "__main__": 7 | print("one.py is being run directly") 8 | else: 9 | print("one.py is being imported into another module") 10 | -------------------------------------------------------------------------------- /06-Modules et Paquets/01-Name_and_Main/two.py: -------------------------------------------------------------------------------- 1 | import one 2 | 3 | print("top-level in two.py") 4 | 5 | one.func() 6 | 7 | if __name__ == "__main__": 8 | print("two.py is being run directly") 9 | else: 10 | print("two.py is being imported into another module") 11 | -------------------------------------------------------------------------------- /07-Erreurs et Exceptions/Gestion des erreurs et des exceptions - Controle de connaissances.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Gestion des erreurs et des exceptions\n", 8 | "## Controle de connaissances" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "### 1er problème\n", 16 | "\n", 17 | "Traitez l'exception produite par le code ci-dessous en utilisant des blocs try et except." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 1, 23 | "metadata": { 24 | "collapsed": false 25 | }, 26 | "outputs": [ 27 | { 28 | "ename": "TypeError", 29 | "evalue": "unsupported operand type(s) for ** or pow(): 'str' and 'int'", 30 | "output_type": "error", 31 | "traceback": [ 32 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 33 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 34 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'a'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'b'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'c'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 35 | "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for ** or pow(): 'str' and 'int'" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "for i in ['a','b','c']:\n", 41 | " print (i**2)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "### 2ème problème\n", 49 | "Gérer l'exception produite par le code ci-dessous en utilisant des blocs **try** et **except**. Ensuite, utilisez un bloc **finally** pour afficher 'Tout est terminé.'." 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 2, 55 | "metadata": { 56 | "collapsed": false 57 | }, 58 | "outputs": [ 59 | { 60 | "ename": "ZeroDivisionError", 61 | "evalue": "integer division or modulo by zero", 62 | "output_type": "error", 63 | "traceback": [ 64 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 65 | "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 66 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mz\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 67 | "\u001b[0;31mZeroDivisionError\u001b[0m: integer division or modulo by zero" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "x = 5\n", 73 | "y = 0\n", 74 | "\n", 75 | "z = x/y" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "### 3ème problème\n", 83 | "\n", 84 | "Ecrire une fonction qui demande un entier et affiche le carré de celui-ci. Utilisez une boucle while avec des blocs try, except et else pour gérer les entrées incorrectes." 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 2, 90 | "metadata": { 91 | "collapsed": false 92 | }, 93 | "outputs": [], 94 | "source": [ 95 | "def demande():\n", 96 | " pass" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 3, 102 | "metadata": { 103 | "collapsed": false 104 | }, 105 | "outputs": [ 106 | { 107 | "name": "stdout", 108 | "output_type": "stream", 109 | "text": [ 110 | "Tapez un entier : \n", 111 | "Une erreur s'est produite ! Merci d'essayer à nouveau !\n", 112 | "Tapez un entier : 4\n", 113 | "Merci, votre nombre au carré est : 16\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "demande()" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "metadata": {}, 124 | "source": [ 125 | "# Bravo !" 126 | ] 127 | } 128 | ], 129 | "metadata": { 130 | "anaconda-cloud": {}, 131 | "kernelspec": { 132 | "display_name": "Python [default]", 133 | "language": "python", 134 | "name": "python3" 135 | }, 136 | "language_info": { 137 | "codemirror_mode": { 138 | "name": "ipython", 139 | "version": 3 140 | }, 141 | "file_extension": ".py", 142 | "mimetype": "text/x-python", 143 | "name": "python", 144 | "nbconvert_exporter": "python", 145 | "pygments_lexer": "ipython3", 146 | "version": "3.5.2" 147 | } 148 | }, 149 | "nbformat": 4, 150 | "nbformat_minor": 0 151 | } 152 | -------------------------------------------------------------------------------- /07-Erreurs et Exceptions/Gestion des erreurs et des exceptions - Solution du controle de connaissances.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Gestion des erreurs et des exceptions\n", 8 | "## Solution du controle de connaissances" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "### 1er problème\n", 16 | "\n", 17 | "Traitez l'exception produite par le code ci-dessous en utilisant des blocs try et except." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 1, 23 | "metadata": { 24 | "collapsed": false 25 | }, 26 | "outputs": [ 27 | { 28 | "name": "stdout", 29 | "output_type": "stream", 30 | "text": [ 31 | "Une erreur s'est produite !\n" 32 | ] 33 | } 34 | ], 35 | "source": [ 36 | "try:\n", 37 | " for i in ['a','b','c']:\n", 38 | " print (i**2)\n", 39 | "except:\n", 40 | " print (\"Une erreur s'est produite !\")" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "### 2ème problème\n", 48 | "Gérer l'exception produite par le code ci-dessous en utilisant des blocs **try** et **except**. Ensuite, utilisez un bloc **finally** pour afficher 'Tout est terminé.'." 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 3, 54 | "metadata": { 55 | "collapsed": false 56 | }, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "On ne peut pas diviser par 0 !\n", 63 | "Tout est terminé !\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "x = 5\n", 69 | "y = 0\n", 70 | "try:\n", 71 | " z = x/y\n", 72 | "except ZeroDivisionError:\n", 73 | " print (\"On ne peut pas diviser par 0 !\")\n", 74 | "finally:\n", 75 | " print ('Tout est terminé !')" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "### 3ème problème\n", 83 | "\n", 84 | "Ecrire une fonction qui demande un entier et affiche le carré de celui-ci. Utilisez une boucle while avec des blocs try, except et else pour gérer les entrées incorrectes." 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 8, 90 | "metadata": { 91 | "collapsed": false 92 | }, 93 | "outputs": [], 94 | "source": [ 95 | "def demande():\n", 96 | " \n", 97 | " while True:\n", 98 | " try:\n", 99 | " n = int(input('Tapez un entier : '))\n", 100 | " except:\n", 101 | " print (\"Une erreur s'est produite ! Merci d'essayer à nouveau !\")\n", 102 | " continue\n", 103 | " else:\n", 104 | " break\n", 105 | " print ('Merci, votre nombre au carré est : ',n**2)" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 9, 111 | "metadata": { 112 | "collapsed": false 113 | }, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "Tapez un entier : e\n", 120 | "Une erreur s'est produite ! Merci d'essayer à nouveau !\n", 121 | "Tapez un entier : A\n", 122 | "Une erreur s'est produite ! Merci d'essayer à nouveau !\n", 123 | "Tapez un entier : 12121\n", 124 | "Merci, votre nombre au carré est : 146918641\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "demande()" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "# Bravo !" 137 | ] 138 | } 139 | ], 140 | "metadata": { 141 | "anaconda-cloud": {}, 142 | "kernelspec": { 143 | "display_name": "Python [default]", 144 | "language": "python", 145 | "name": "python3" 146 | }, 147 | "language_info": { 148 | "codemirror_mode": { 149 | "name": "ipython", 150 | "version": 3 151 | }, 152 | "file_extension": ".py", 153 | "mimetype": "text/x-python", 154 | "name": "python", 155 | "nbconvert_exporter": "python", 156 | "pygments_lexer": "ipython3", 157 | "version": "3.5.2" 158 | } 159 | }, 160 | "nbformat": 4, 161 | "nbformat_minor": 0 162 | } 163 | -------------------------------------------------------------------------------- /08-Deuxième Projet/Milestone Project 2 - Développer un jeu de Blackjack.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Deuxième projet d'étape - jeu de Blackjack\n", 8 | "Dans ce projet, vous allez créer un jeu de cartes BlackJack complet en Python.\n", 9 | "\n", 10 | "Voici le détail de votre mission :\n", 11 | "\n", 12 | "* Vous allez créer un jeu de [BlackJack](https://fr.wikipedia.org/wiki/Blackjack_%28jeu%29) en mode texte.\n", 13 | "* Le jeu devra avoir un joueur contre une banque automatique.\n", 14 | "* Le joueur peut passer ou prendre une carte.\n", 15 | "* Le joueur doit pouvoir choisir le montant du pari.\n", 16 | "* Vous devez garder en mémoire le montant de l'argent du joueur.\n", 17 | "* Vous devez informer le joueur des gains, des pertes, etc.\n", 18 | "\n", 19 | "Et très important :\n", 20 | "\n", 21 | "* **Vous devez utiliser la programmation objet et les classes dans une partie de votre jeu. Vous ne devez pas vous limiter à utiliser des fonctions. Utilisez des classes pour vous aider à définir le sabot et la main du joueur. Il existe de nombreuses façons de le faire, alors bonne exploration !**\n", 22 | "\n", 23 | "N'hésitez pas à développer ce jeu: essayez d'autoriser plusieurs joueurs. Essayez d'ajouter la possibilité de Doubler et les splits ! N'oubliez pas que vous êtes libre d'utiliser les ressources que vous voulez et comme toujours :\n", 24 | "\n", 25 | "# Amusez vous bien !" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": { 32 | "collapsed": true 33 | }, 34 | "outputs": [], 35 | "source": [] 36 | } 37 | ], 38 | "metadata": { 39 | "anaconda-cloud": {}, 40 | "kernelspec": { 41 | "display_name": "Python [default]", 42 | "language": "python", 43 | "name": "python3" 44 | }, 45 | "language_info": { 46 | "codemirror_mode": { 47 | "name": "ipython", 48 | "version": 3 49 | }, 50 | "file_extension": ".py", 51 | "mimetype": "text/x-python", 52 | "name": "python", 53 | "nbconvert_exporter": "python", 54 | "pygments_lexer": "ipython3", 55 | "version": "3.5.2" 56 | } 57 | }, 58 | "nbformat": 4, 59 | "nbformat_minor": 0 60 | } 61 | -------------------------------------------------------------------------------- /09-Fonctions Intégrées/All() et any().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# all() et any()" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "all() et any() sont des fonctions intégrées de Python qui permettent de vérifier facilement l'état de booléen dans un objet itérable. All() renverra True si tous les éléments de l'objet iterable sont True. Elle est équivalente au code de cette fonction:\n", 15 | "\n", 16 | " def all(iterable):\n", 17 | " for element in iterable:\n", 18 | " if not element:\n", 19 | " return False\n", 20 | " return True\n", 21 | " \n", 22 | "any() renvoie True si au moins un des élements de l'objet iterable est True. Elle est équivalente au code de cette fonction:\n", 23 | "\n", 24 | " def any(iterable):\n", 25 | " for element in iterable:\n", 26 | " if element:\n", 27 | " return True\n", 28 | " return False\n", 29 | " " 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "Voyons quelques exemples de ces fonctions. Ils son assez simples:" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 4, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "lst = [True,True,False,True]" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 5, 53 | "metadata": { 54 | "collapsed": false 55 | }, 56 | "outputs": [ 57 | { 58 | "data": { 59 | "text/plain": [ 60 | "False" 61 | ] 62 | }, 63 | "execution_count": 5, 64 | "metadata": {}, 65 | "output_type": "execute_result" 66 | } 67 | ], 68 | "source": [ 69 | "all(lst)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "Renvoie False parce qu'un élément n'est pas True." 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 6, 82 | "metadata": { 83 | "collapsed": false 84 | }, 85 | "outputs": [ 86 | { 87 | "data": { 88 | "text/plain": [ 89 | "True" 90 | ] 91 | }, 92 | "execution_count": 6, 93 | "metadata": {}, 94 | "output_type": "execute_result" 95 | } 96 | ], 97 | "source": [ 98 | "any(lst)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "Renvoie True parce qu'au moins un des éléments est True" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "C'est fait, vous devez maintenant être capable d'utiliser any() et all() dans votre code." 113 | ] 114 | } 115 | ], 116 | "metadata": { 117 | "anaconda-cloud": {}, 118 | "kernelspec": { 119 | "display_name": "Python 3", 120 | "language": "python", 121 | "name": "python3" 122 | }, 123 | "language_info": { 124 | "codemirror_mode": { 125 | "name": "ipython", 126 | "version": 3 127 | }, 128 | "file_extension": ".py", 129 | "mimetype": "text/x-python", 130 | "name": "python", 131 | "nbconvert_exporter": "python", 132 | "pygments_lexer": "ipython3", 133 | "version": "3.6.0" 134 | } 135 | }, 136 | "nbformat": 4, 137 | "nbformat_minor": 0 138 | } 139 | -------------------------------------------------------------------------------- /09-Fonctions Intégrées/Complex.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# complex()\n", 8 | "\n", 9 | "Complex() renvoie un nombre complexe avec la valeur *réel + imaginaire * 1j* ou convertit une chaîne ou un nombre en nombre complexe.\n", 10 | "\n", 11 | "Si le premier paramètre est une chaîne, il sera interprété comme un nombre complexe et la fonction doit être appelée sans second paramètre. Le second paramètre ne peut jamais être une chaîne. Chaque argument peut être n'importe quel type numérique (y compris complexe). Si la partie imaginaire est omise, elle est par défaut nulle et le constructeur sert de conversion numérique comme int ou float. Si les deux arguments sont omis, la fonction renvoie 0j.\n", 12 | "\n", 13 | "Si vous faites des mathématiques ou de l'ingénierie qui nécessite des nombres complexes (comme la dynamique, les systèmes de contrôle, ou l'impédance de circuit), c'est un outil utile à avoir en Python.\n", 14 | "\n", 15 | "Voyons quelques exemples:" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": { 22 | "collapsed": false 23 | }, 24 | "outputs": [ 25 | { 26 | "data": { 27 | "text/plain": [ 28 | "(2+3j)" 29 | ] 30 | }, 31 | "execution_count": 1, 32 | "metadata": {}, 33 | "output_type": "execute_result" 34 | } 35 | ], 36 | "source": [ 37 | "# Création de 2+3j\n", 38 | "complex(2,3)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 2, 44 | "metadata": { 45 | "collapsed": false 46 | }, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "(10+1j)" 52 | ] 53 | }, 54 | "execution_count": 2, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "complex(10,1)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "On peut aussi passer une chaine :" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 1, 73 | "metadata": { 74 | "collapsed": false 75 | }, 76 | "outputs": [ 77 | { 78 | "data": { 79 | "text/plain": [ 80 | "(12+2j)" 81 | ] 82 | }, 83 | "execution_count": 1, 84 | "metadata": {}, 85 | "output_type": "execute_result" 86 | } 87 | ], 88 | "source": [ 89 | "complex('12+2j')" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "C'est vraiment tout ce que l'on peut dire pour cette fonction très utile. Gardez cela à l'esprit si vous avez jamais affaire à des nombres complexes en Python !" 97 | ] 98 | } 99 | ], 100 | "metadata": { 101 | "anaconda-cloud": {}, 102 | "kernelspec": { 103 | "display_name": "Python [default]", 104 | "language": "python", 105 | "name": "python3" 106 | }, 107 | "language_info": { 108 | "codemirror_mode": { 109 | "name": "ipython", 110 | "version": 3 111 | }, 112 | "file_extension": ".py", 113 | "mimetype": "text/x-python", 114 | "name": "python", 115 | "nbconvert_exporter": "python", 116 | "pygments_lexer": "ipython3", 117 | "version": "3.5.2" 118 | } 119 | }, 120 | "nbformat": 4, 121 | "nbformat_minor": 0 122 | } 123 | -------------------------------------------------------------------------------- /09-Fonctions Intégrées/Controle de connaissances sur les fonctions intégrées.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Contrôle de connaissances sur les fonctions intégrées\n", 8 | "\n", 9 | "### Pour ce test, vous devrez utiliser les fonctions intégrées de Python pour écrire les fonctions demandées en une seule ligne." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "### 1er problème\n", 17 | "\n", 18 | "Utilisez map() pour créer une fonction qui donne la longueur de chaque mot dans une phrase\n", 19 | "(mots séparés par des espaces) et renvoie les valeurs dans une liste.\n", 20 | "\n", 21 | "La fonction aura une chaîne en entrée, et la liste d'entiers en sortie." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": { 28 | "collapsed": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "def longueur_mots(phrase):\n", 33 | " pass" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 6, 39 | "metadata": { 40 | "collapsed": false 41 | }, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "[6, 3, 2, 8, 2, 3, 4, 4, 5, 6]" 47 | ] 48 | }, 49 | "execution_count": 6, 50 | "metadata": {}, 51 | "output_type": "execute_result" 52 | } 53 | ], 54 | "source": [ 55 | "longueur_mots(\"Quelle est la longueur de ces mots dans cette phrase\")" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "### 2e problème\n", 63 | "\n", 64 | "Utilisez filter() pour renvoyer les mots d'une liste qui commencent par une lettre particulière donnée également en paramètre." 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 2, 70 | "metadata": { 71 | "collapsed": true 72 | }, 73 | "outputs": [], 74 | "source": [ 75 | "def filtre_mots(liste_mots, lettre):\n", 76 | " pass" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 12, 82 | "metadata": { 83 | "collapsed": false 84 | }, 85 | "outputs": [ 86 | { 87 | "data": { 88 | "text/plain": [ 89 | "['chat', 'chien', 'cheval', 'canard']" 90 | ] 91 | }, 92 | "execution_count": 12, 93 | "metadata": {}, 94 | "output_type": "execute_result" 95 | } 96 | ], 97 | "source": [ 98 | "l = ['poisson','chat','chien','hamster','cheval','vache','canard','hérisson','poule']\n", 99 | "list(filtre_mots(l,'c'))" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "### 3e problème\n", 107 | "\n", 108 | "Utilisez zip() et la compréhension de liste pour renvoyer une liste de même longueur pour laquelle chaque valeur est le résultat de la concaténation des valeurs des listes données en paramètre, séparées par un connecteur.\n", 109 | "\n", 110 | "Regardez l'exemple ci-dessous :" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 3, 116 | "metadata": { 117 | "collapsed": true 118 | }, 119 | "outputs": [], 120 | "source": [ 121 | "def assemble(L1, L2, connecteur):\n", 122 | " pass" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 16, 128 | "metadata": { 129 | "collapsed": false 130 | }, 131 | "outputs": [ 132 | { 133 | "data": { 134 | "text/plain": [ 135 | "['A-a', 'B-b']" 136 | ] 137 | }, 138 | "execution_count": 16, 139 | "metadata": {}, 140 | "output_type": "execute_result" 141 | } 142 | ], 143 | "source": [ 144 | "assemble(['A','B'],['a','b'],'-')" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "### 4e problème\n", 152 | "\n", 153 | "Utilisez enumerate() et d'autres compétences pour renvoyer un dictionnaire qui a les valeurs de la liste comme clefs et l'index de ces entrées comme valeurs. Vous pouvez assumer qu'une valeur n'apparait qu'une seule fois dans une liste donnée." 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 17, 159 | "metadata": { 160 | "collapsed": true 161 | }, 162 | "outputs": [], 163 | "source": [ 164 | "def d_list(L):\n", 165 | " pass" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 18, 171 | "metadata": { 172 | "collapsed": false 173 | }, 174 | "outputs": [ 175 | { 176 | "data": { 177 | "text/plain": [ 178 | "{'a': 0, 'b': 1, 'c': 2}" 179 | ] 180 | }, 181 | "execution_count": 18, 182 | "metadata": {}, 183 | "output_type": "execute_result" 184 | } 185 | ], 186 | "source": [ 187 | "d_list(['a','b','c'])" 188 | ] 189 | }, 190 | { 191 | "cell_type": "markdown", 192 | "metadata": {}, 193 | "source": [ 194 | "### 5e problème\n", 195 | "\n", 196 | "Use enumerate() et d'autres compétences pour renvoyer la valeur du nombre d'items dans une liste pour lesquels la valeur est égale à l'index." 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 21, 202 | "metadata": { 203 | "collapsed": true 204 | }, 205 | "outputs": [], 206 | "source": [ 207 | "def compte_index(L):\n", 208 | " pass" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 20, 214 | "metadata": { 215 | "collapsed": false 216 | }, 217 | "outputs": [ 218 | { 219 | "data": { 220 | "text/plain": [ 221 | "4" 222 | ] 223 | }, 224 | "execution_count": 20, 225 | "metadata": {}, 226 | "output_type": "execute_result" 227 | } 228 | ], 229 | "source": [ 230 | "compte_index([0,2,2,1,5,5,6,10])" 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "metadata": {}, 236 | "source": [ 237 | "# Bravo, joli travail !" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "metadata": { 244 | "collapsed": true 245 | }, 246 | "outputs": [], 247 | "source": [] 248 | } 249 | ], 250 | "metadata": { 251 | "anaconda-cloud": {}, 252 | "kernelspec": { 253 | "display_name": "Python [default]", 254 | "language": "python", 255 | "name": "python3" 256 | }, 257 | "language_info": { 258 | "codemirror_mode": { 259 | "name": "ipython", 260 | "version": 3 261 | }, 262 | "file_extension": ".py", 263 | "mimetype": "text/x-python", 264 | "name": "python", 265 | "nbconvert_exporter": "python", 266 | "pygments_lexer": "ipython3", 267 | "version": "3.5.2" 268 | } 269 | }, 270 | "nbformat": 4, 271 | "nbformat_minor": 0 272 | } 273 | -------------------------------------------------------------------------------- /09-Fonctions Intégrées/Enumerate.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# enumerate()\n", 8 | "\n", 9 | "Dans cette leçon, nous allons voir une fonction intégrée extrêmement utile : enumerate(). Elle permet de garder un décompte en itérant à travers un objet. Pour ce faire, elle renvoie un tuple sous la forme (compteur, élement). La fonction elle-même est équivalente à :\n", 10 | "\n", 11 | " def enumerate(sequence, start=0):\n", 12 | " n = start\n", 13 | " for element in sequence:\n", 14 | " yield n, element\n", 15 | " n += 1\n", 16 | "\n", 17 | "## Exemple" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 1, 23 | "metadata": { 24 | "collapsed": false 25 | }, 26 | "outputs": [ 27 | { 28 | "name": "stdout", 29 | "output_type": "stream", 30 | "text": [ 31 | "0 a\n", 32 | "1 b\n", 33 | "2 c\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "lst = ['a','b','c']\n", 39 | "\n", 40 | "for nombre,item in enumerate(lst):\n", 41 | " print (nombre, item)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "Enumerate() est particulièrement utile lorsque vous devez garder en mémoire une sorte de suivi. Par exemple:" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 4, 54 | "metadata": { 55 | "collapsed": false 56 | }, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "a\n", 63 | "b\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "for compte,item in enumerate(lst):\n", 69 | " if compte >= 2:\n", 70 | " break\n", 71 | " else:\n", 72 | " print (item)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "Bravo ! Vous devez maintenant avoir une bonne compréhenson de enumerate et des pssibilités qu'elle offre." 80 | ] 81 | } 82 | ], 83 | "metadata": { 84 | "anaconda-cloud": {}, 85 | "kernelspec": { 86 | "display_name": "Python [default]", 87 | "language": "python", 88 | "name": "python3" 89 | }, 90 | "language_info": { 91 | "codemirror_mode": { 92 | "name": "ipython", 93 | "version": 3 94 | }, 95 | "file_extension": ".py", 96 | "mimetype": "text/x-python", 97 | "name": "python", 98 | "nbconvert_exporter": "python", 99 | "pygments_lexer": "ipython3", 100 | "version": "3.5.2" 101 | } 102 | }, 103 | "nbformat": 4, 104 | "nbformat_minor": 0 105 | } 106 | -------------------------------------------------------------------------------- /09-Fonctions Intégrées/Filter.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Filter\n", 8 | "\n", 9 | "La fonction filter(fonction, liste) procure un moyen simple de filtrer tous les éléments d'un objet iterable, pour lequel la fonction testée renvoie True.\n", 10 | "\n", 11 | "La fonction filter(fonction(), l) prend comme premier argument une fonction. Elle renvoie une valeur booléenne (True ou False). Cette fonction sera appliquée à chaque élément de l'objet itérable. L'élément de l'objet iterable ne sera inclus dans le résultat que si la fonction renvoie True.\n", 12 | "\n", 13 | "Voyons quelques exemples:" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 2, 19 | "metadata": { 20 | "collapsed": true 21 | }, 22 | "outputs": [], 23 | "source": [ 24 | "# Créons d'abord une fonction\n", 25 | "def verifie_pair(num):\n", 26 | " if num%2 ==0:\n", 27 | " return True" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "Maintenant, nous allons filtrer une liste de numéros. Note: mettre la fonction dans le filtre sans aucune parenthèse peut sembler étrange, mais gardez à l'esprit que les fonctions sont aussi des objets." 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 4, 40 | "metadata": { 41 | "collapsed": false 42 | }, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/plain": [ 47 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" 48 | ] 49 | }, 50 | "execution_count": 4, 51 | "metadata": {}, 52 | "output_type": "execute_result" 53 | } 54 | ], 55 | "source": [ 56 | "lst =range(20)\n", 57 | "\n", 58 | "list(filter(verifie_pair,lst))" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "Filter() est souvent utilisé avec les fonctions lambda, parce que nous utilisons généralement filter pour un petit travail rapide pour lequel nous ne voulons pas écrire une fonction complètement. Reprenons l'exemple ci-dessus en utilisant une expression lambda:" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 6, 71 | "metadata": { 72 | "collapsed": false 73 | }, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]" 79 | ] 80 | }, 81 | "execution_count": 6, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "list(filter(lambda x: x%2==0,lst))" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "Bravo ! Vous devez maintenant avoir une bonne compréhension de filter() et comment l'utiliser dans votre code!" 95 | ] 96 | } 97 | ], 98 | "metadata": { 99 | "anaconda-cloud": {}, 100 | "kernelspec": { 101 | "display_name": "Python 3", 102 | "language": "python", 103 | "name": "python3" 104 | }, 105 | "language_info": { 106 | "codemirror_mode": { 107 | "name": "ipython", 108 | "version": 3 109 | }, 110 | "file_extension": ".py", 111 | "mimetype": "text/x-python", 112 | "name": "python", 113 | "nbconvert_exporter": "python", 114 | "pygments_lexer": "ipython3", 115 | "version": "3.6.0" 116 | } 117 | }, 118 | "nbformat": 4, 119 | "nbformat_minor": 0 120 | } 121 | -------------------------------------------------------------------------------- /09-Fonctions Intégrées/Map.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# map()\n", 8 | "\n", 9 | "map() est une fonction qui prend deux arguments: une fonction et une séquence itérables. Sous la forme:\n", 10 | " map(fonction, séquence)\n", 11 | " \n", 12 | "Le premier argument est le nom d'une fonction et le second une séquence (par exemple une liste). La fonction map() applique la fonction passée en entrée à tous les éléments de la séquence. Elle renvoie une nouvelle liste contenant les éléments modifiés par la fonction.\n", 13 | "\n", 14 | "Quand nous avons vu la compréhension de la liste, nous avons créé une petite expression pour convertir Fahrenheit en Celsius. Nous pouvons refaire la même chose avec map().\n", 15 | "\n", 16 | "Nous allons commencer par deux fonctions:" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 30, 22 | "metadata": { 23 | "collapsed": true 24 | }, 25 | "outputs": [], 26 | "source": [ 27 | "def fahrenheit(T):\n", 28 | " return ((float(9)/5)*T + 32)\n", 29 | "def celsius(T):\n", 30 | " return (float(5)/9)*(T-32)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "Voyons map() en action:" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 36, 43 | "metadata": { 44 | "collapsed": false 45 | }, 46 | "outputs": [ 47 | { 48 | "data": { 49 | "text/plain": [ 50 | "[32.0, 72.5, 104.0, 212.0]" 51 | ] 52 | }, 53 | "execution_count": 36, 54 | "metadata": {}, 55 | "output_type": "execute_result" 56 | } 57 | ], 58 | "source": [ 59 | "température = [0, 22.5, 40,100]\n", 60 | "\n", 61 | "F_temps = list(map(fahrenheit, température))\n", 62 | "\n", 63 | "# Affichage\n", 64 | "F_temps" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 38, 70 | "metadata": { 71 | "collapsed": false 72 | }, 73 | "outputs": [ 74 | { 75 | "data": { 76 | "text/plain": [ 77 | "[0.0, 22.5, 40.0, 100.0]" 78 | ] 79 | }, 80 | "execution_count": 38, 81 | "metadata": {}, 82 | "output_type": "execute_result" 83 | } 84 | ], 85 | "source": [ 86 | "# Conversion inverse\n", 87 | "\n", 88 | "list(map(celsius, F_temps))" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "Dans l'exemple ci-dessus, nous n'avons pas utilisé d'expression lambda. En utilisant une expression lambda, nous n'aurions pas eu à définir les fonctions fahrenheit() et celsius()." 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 40, 101 | "metadata": { 102 | "collapsed": false 103 | }, 104 | "outputs": [ 105 | { 106 | "data": { 107 | "text/plain": [ 108 | "[0.0, 22.5, 40.0, 100.0]" 109 | ] 110 | }, 111 | "execution_count": 40, 112 | "metadata": {}, 113 | "output_type": "execute_result" 114 | } 115 | ], 116 | "source": [ 117 | "list(map(lambda x: (5.0/9)*(x - 32), F_temps))" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "Bravo ! Nous avons obtenu le même résultat ! \n", 125 | "map() est très couramment utilisée avec des expressions lambda car le but final de map() est d'économiser les efforts pour écrire du code et cela permet d'éviter de créer des boucles." 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "map() peut être appliqué à plusieurs objets iterable mais qui doivent avoir la même longueur.\n", 133 | "\n", 134 | "\n", 135 | "Par exemple, si nous travaillons avec deux listes, map() appliquera la fonction lambda aux éléments de la liste d'arguments, c'est-à-dire qu'elle s'appliquera d'abord aux éléments avec l'indice 0, puis aux éléments avec le 1er indice et ainsi de suite jusqu'à ce que n-ième indice soit atteint.\n", 136 | "\n", 137 | "Par exemple, voyons comment utiliser map() avec une expression lambda à deux listes:" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 42, 143 | "metadata": { 144 | "collapsed": false 145 | }, 146 | "outputs": [ 147 | { 148 | "data": { 149 | "text/plain": [ 150 | "[6, 8, 10, 12]" 151 | ] 152 | }, 153 | "execution_count": 42, 154 | "metadata": {}, 155 | "output_type": "execute_result" 156 | } 157 | ], 158 | "source": [ 159 | "a = [1,2,3,4]\n", 160 | "b = [5,6,7,8]\n", 161 | "c = [9,10,11,12]\n", 162 | "\n", 163 | "list(map(lambda x,y:x+y,a,b))" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 13, 169 | "metadata": { 170 | "collapsed": false 171 | }, 172 | "outputs": [ 173 | { 174 | "data": { 175 | "text/plain": [ 176 | "[15, 18, 21, 24]" 177 | ] 178 | }, 179 | "execution_count": 13, 180 | "metadata": {}, 181 | "output_type": "execute_result" 182 | } 183 | ], 184 | "source": [ 185 | "# Maintenant avec trois listes\n", 186 | "list(map(lambda x,y,z:x+y+z, a,b,c)" 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": {}, 192 | "source": [ 193 | "Nous pouvons voir dans l'exemple ci-dessus que le paramètre x obtient ses valeurs de la liste a, alors que y obtient ses valeurs de b et z de la liste c. Vous pouvez maintenant développer votre propre exemple pour vous assurer de bien comprendre comment utiliser map() avec plus d'un b-objet itérable.\n", 194 | "\n", 195 | "Bravo ! Vous devez maintenant avoir une connaissance de base de la fonction map()." 196 | ] 197 | } 198 | ], 199 | "metadata": { 200 | "anaconda-cloud": {}, 201 | "kernelspec": { 202 | "display_name": "Python 3", 203 | "language": "python", 204 | "name": "python3" 205 | }, 206 | "language_info": { 207 | "codemirror_mode": { 208 | "name": "ipython", 209 | "version": 3 210 | }, 211 | "file_extension": ".py", 212 | "mimetype": "text/x-python", 213 | "name": "python", 214 | "nbconvert_exporter": "python", 215 | "pygments_lexer": "ipython3", 216 | "version": "3.6.0" 217 | } 218 | }, 219 | "nbformat": 4, 220 | "nbformat_minor": 0 221 | } 222 | -------------------------------------------------------------------------------- /09-Fonctions Intégrées/Solutions du controle de connaissances sur les fonctions intégrées.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Solutions du contrôle de connaissances sur les fonctions intégrées\n", 8 | "\n", 9 | "### Pour ce test, vous devrez utiliser les fonctions intégrées de Python pour écrire les fonctions demandées en une seule ligne." 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "### 1er problème\n", 17 | "\n", 18 | "Utilisez map() pour créer une fonction qui donne la longueur de chaque mot dans une phrase\n", 19 | "(mots séparés par des espaces) et renvoie les valeurs dans une liste.\n", 20 | "\n", 21 | "La fonction aura une chaîne en entrée, et la liste d'entiers en sortie." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 5, 27 | "metadata": { 28 | "collapsed": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "def longueur_mots(phrase):\n", 33 | " \n", 34 | " return list(map(len, phrase.split()))" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 6, 40 | "metadata": { 41 | "collapsed": false 42 | }, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/plain": [ 47 | "[6, 3, 2, 8, 2, 3, 4, 4, 5, 6]" 48 | ] 49 | }, 50 | "execution_count": 6, 51 | "metadata": {}, 52 | "output_type": "execute_result" 53 | } 54 | ], 55 | "source": [ 56 | "longueur_mots(\"Quelle est la longueur de ces mots dans cette phrase\")" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "### 2e problème\n", 64 | "\n", 65 | "Utilisez filter() pour renvoyer les mots d'une liste qui commencent par une lettre particulière donnée également en paramètre." 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 11, 71 | "metadata": { 72 | "collapsed": true 73 | }, 74 | "outputs": [], 75 | "source": [ 76 | "def filtre_mots(liste_mots, lettre):\n", 77 | " \n", 78 | " return filter(lambda mot: mot[0]==lettre,liste_mots)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 12, 84 | "metadata": { 85 | "collapsed": false 86 | }, 87 | "outputs": [ 88 | { 89 | "data": { 90 | "text/plain": [ 91 | "['chat', 'chien', 'cheval', 'canard']" 92 | ] 93 | }, 94 | "execution_count": 12, 95 | "metadata": {}, 96 | "output_type": "execute_result" 97 | } 98 | ], 99 | "source": [ 100 | "l = ['poisson','chat','chien','hamster','cheval','vache','canard','hérisson','poule']\n", 101 | "list(filtre_mots(l,'c'))" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "### 3e problème\n", 109 | "\n", 110 | "Utilisez zip() et la compréhension de liste pour renvoyer une liste de même longueur pour laquelle chaque valeur est le résultat de la concaténation des valeurs des listes données en paramètre, séparées par un connecteur.\n", 111 | "\n", 112 | "Regardez l'exemple ci-dessous :" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 15, 118 | "metadata": { 119 | "collapsed": true 120 | }, 121 | "outputs": [], 122 | "source": [ 123 | "def assemble(L1, L2, connecteur):\n", 124 | " \n", 125 | " return [mot1+connecteur+mot2 for (mot1,mot2) in zip(L1,L2)]" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 16, 131 | "metadata": { 132 | "collapsed": false 133 | }, 134 | "outputs": [ 135 | { 136 | "data": { 137 | "text/plain": [ 138 | "['A-a', 'B-b']" 139 | ] 140 | }, 141 | "execution_count": 16, 142 | "metadata": {}, 143 | "output_type": "execute_result" 144 | } 145 | ], 146 | "source": [ 147 | "assemble(['A','B'],['a','b'],'-')" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "### 4e problème\n", 155 | "\n", 156 | "Utilisez enumerate() et d'autres compétences pour renvoyer un dictionnaire qui a les valeurs de la liste comme clefs et l'index de ces entrées comme valeurs. Vous pouvez assumer qu'une valeur n'apparait qu'une seule fois dans une liste donnée." 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 17, 162 | "metadata": { 163 | "collapsed": true 164 | }, 165 | "outputs": [], 166 | "source": [ 167 | "def d_list(L):\n", 168 | " \n", 169 | " return {clef:valeur for valeur,clef in enumerate(L)}" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 18, 175 | "metadata": { 176 | "collapsed": false 177 | }, 178 | "outputs": [ 179 | { 180 | "data": { 181 | "text/plain": [ 182 | "{'a': 0, 'b': 1, 'c': 2}" 183 | ] 184 | }, 185 | "execution_count": 18, 186 | "metadata": {}, 187 | "output_type": "execute_result" 188 | } 189 | ], 190 | "source": [ 191 | "d_list(['a','b','c'])" 192 | ] 193 | }, 194 | { 195 | "cell_type": "markdown", 196 | "metadata": {}, 197 | "source": [ 198 | "### 5e problème\n", 199 | "\n", 200 | "Use enumerate() et d'autres compétences pour renvoyer la valeur du nombre d'items dans une liste pour lesquels la valeur est égale à l'index." 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 21, 206 | "metadata": { 207 | "collapsed": true 208 | }, 209 | "outputs": [], 210 | "source": [ 211 | "def compte_index(L):\n", 212 | " \n", 213 | " return len([num for compte,num in enumerate(L) if num == compte])" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 20, 219 | "metadata": { 220 | "collapsed": false 221 | }, 222 | "outputs": [ 223 | { 224 | "data": { 225 | "text/plain": [ 226 | "4" 227 | ] 228 | }, 229 | "execution_count": 20, 230 | "metadata": {}, 231 | "output_type": "execute_result" 232 | } 233 | ], 234 | "source": [ 235 | "compte_index([0,2,2,1,5,5,6,10])" 236 | ] 237 | }, 238 | { 239 | "cell_type": "markdown", 240 | "metadata": {}, 241 | "source": [ 242 | "# Bravo, joli travail !" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": null, 248 | "metadata": { 249 | "collapsed": true 250 | }, 251 | "outputs": [], 252 | "source": [] 253 | } 254 | ], 255 | "metadata": { 256 | "anaconda-cloud": {}, 257 | "kernelspec": { 258 | "display_name": "Python [default]", 259 | "language": "python", 260 | "name": "python3" 261 | }, 262 | "language_info": { 263 | "codemirror_mode": { 264 | "name": "ipython", 265 | "version": 3 266 | }, 267 | "file_extension": ".py", 268 | "mimetype": "text/x-python", 269 | "name": "python", 270 | "nbconvert_exporter": "python", 271 | "pygments_lexer": "ipython3", 272 | "version": "3.5.2" 273 | } 274 | }, 275 | "nbformat": 4, 276 | "nbformat_minor": 0 277 | } 278 | -------------------------------------------------------------------------------- /10-Décorateurs/Approfondissements sur les décorateurs .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Approfondissements sur les décorateurs \n", 8 | "\n", 9 | "## Projet personnel sur les décorateurs (optionnel)\n", 10 | "\n", 11 | "Ce projet est facultatif, vous ne rencontrerez sans doute pas de décorateurs avant longtemps dans votre carrière de codeur. \n", 12 | "\n", 13 | "Consultez d'abord le Framework Web [Flask](http://flask.pocoo.org/). Vous pouvez utiliser Flask pour créer des pages Web avec Python (il suffit pour cela de connaitre un petit peu HTML et CSS) et il utilise beaucoup de décorateurs dans son propre code ! Vous pouvez en apprendre plus sur comment ils utilisent les [décorateurs](http://flask.pocoo.org/docs/0.10/patterns/viewdecorators/). Ne vous inquiétez pas si vous ne comprenez pas tout sur Flask, le point principal de ce travail facultatif est que vous compreniez comment les décorateurs sont employés dans le cadre Web. De cette façon, si vous décidez de devenir un Dévelopeur Python «Full-Stack» pour le Web, vous ne resterez pas longtemps perplexe devant les décorateurs. \n", 14 | "\n", 15 | "Vous pouvez également consulter [Django](https://www.djangoproject.com/) un autre (et plus populaire) framework web pour Python qui est un peu plus complexe.\n", 16 | "\n", 17 | "## Quelques informations supplémentaires:\n", 18 | "### framework\n", 19 | "\n", 20 | "Un **framework** est un type de bibliothèque logicielle qui fournit des fonctionnalités génériques qui peuvent être utilisées par le programmeur pour créer des applications plus efficacement. Flask et Django sont de bons exemples de frameworks destinés au développement web.\n", 21 | "\n", 22 | "### API\n", 23 | "Un framework est plus qu'une simple bibliothèque ou Interface Applicative de Programme (*Application Program Interface ou API*). Une API est un logiciel que le développeur peut utiliser dans son application. Un framework est plus large : votre application entière est structurée autour du framework (c'est-à-dire qu'elle fournit le cadre autour duquel vous construisez votre logiciel).\n", 24 | "\n", 25 | "## Bravo !" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": { 32 | "collapsed": true 33 | }, 34 | "outputs": [], 35 | "source": [] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": { 41 | "collapsed": true 42 | }, 43 | "outputs": [], 44 | "source": [] 45 | } 46 | ], 47 | "metadata": { 48 | "anaconda-cloud": {}, 49 | "kernelspec": { 50 | "display_name": "Python 3", 51 | "language": "python", 52 | "name": "python3" 53 | }, 54 | "language_info": { 55 | "codemirror_mode": { 56 | "name": "ipython", 57 | "version": 3 58 | }, 59 | "file_extension": ".py", 60 | "mimetype": "text/x-python", 61 | "name": "python", 62 | "nbconvert_exporter": "python", 63 | "pygments_lexer": "ipython3", 64 | "version": "3.6.0" 65 | } 66 | }, 67 | "nbformat": 4, 68 | "nbformat_minor": 0 69 | } 70 | -------------------------------------------------------------------------------- /11-Itérateurs et Générateurs/Devoir sur les iterateurs et les générateurs - Solution.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Devoir sur les iterateurs et les générateurs \n", 8 | "## Solutions\n", 9 | "\n", 10 | "### 1er problème\n", 11 | "\n", 12 | "Créer un générateur qui génère les carrés de nombres jusqu'à un certain nombre N." 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 1, 18 | "metadata": { 19 | "collapsed": true 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "def gensquares(N):\n", 24 | " for i in range(N):\n", 25 | " yield i ** 2" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "0\n", 38 | "1\n", 39 | "4\n", 40 | "9\n", 41 | "16\n", 42 | "25\n", 43 | "36\n", 44 | "49\n", 45 | "64\n", 46 | "81\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "for x in gensquares(10):\n", 52 | " print (x)" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": {}, 58 | "source": [ 59 | "### 2ième problème\n", 60 | "\n", 61 | "Créez un générateur qui donne «n» nombres aléatoires entre un nombre de départ et un nombre d'arrivée (qui sont les pramètres d'entrée).\n", 62 | "Remarque: utilisez la bibliothèque random.\n", 63 | "\n", 64 | "Par exemple:" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 3, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "data": { 74 | "text/plain": [ 75 | "6" 76 | ] 77 | }, 78 | "execution_count": 3, 79 | "metadata": {}, 80 | "output_type": "execute_result" 81 | } 82 | ], 83 | "source": [ 84 | "import random\n", 85 | "\n", 86 | "random.randint(1,10)" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 4, 92 | "metadata": { 93 | "collapsed": true 94 | }, 95 | "outputs": [], 96 | "source": [ 97 | "def rand_num(départ,arrivée,n):\n", 98 | " \n", 99 | " for i in range(n):\n", 100 | " yield random.randint(départ, arrivée)" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 6, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "8\n", 113 | "5\n", 114 | "1\n", 115 | "3\n", 116 | "7\n", 117 | "1\n", 118 | "3\n", 119 | "9\n", 120 | "2\n", 121 | "9\n", 122 | "3\n", 123 | "1\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "for num in rand_num(1,10,12):\n", 129 | " print (num)" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "### 3ième problème\n", 137 | "\n", 138 | "Utilisez la fonction iter () pour convertir la chaîne ci-dessous" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 7, 144 | "metadata": {}, 145 | "outputs": [ 146 | { 147 | "name": "stdout", 148 | "output_type": "stream", 149 | "text": [ 150 | "b\n" 151 | ] 152 | } 153 | ], 154 | "source": [ 155 | "s = 'bonjour'\n", 156 | "\n", 157 | "s = iter(s)\n", 158 | "\n", 159 | "print (next(s))" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": {}, 165 | "source": [ 166 | "### 4ième problème\n", 167 | "\n", 168 | "Expliquez un cas d'utilisation pour un générateur en utilisant une déclaration yield plutôt que d'utiliser une fonction normale avec une instruction de retour.\n", 169 | "\n", 170 | "**If the output has the potential of taking up a large amount of memory and you only intend to iterate through it, you would want to use a generator. (Multiple answers are acceptable here!)**" 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": {}, 176 | "source": [ 177 | "### Crédits supplémentaires !\n", 178 | "Pouvez-vous expliquer ce que *gencomp* est dans le code ci-dessous?\n", 179 | "(Note: Nous n'avons jamais couvert cela en cours ! Vous devrez faire quelques appels à Google et Stack Overflow !)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 18, 185 | "metadata": {}, 186 | "outputs": [ 187 | { 188 | "name": "stdout", 189 | "output_type": "stream", 190 | "text": [ 191 | "4\n", 192 | "5\n" 193 | ] 194 | } 195 | ], 196 | "source": [ 197 | "ma_liste = [1,2,3,4,5]\n", 198 | "\n", 199 | "gencomp = (item for item in ma_liste if item > 3)\n", 200 | "\n", 201 | "for item in gencomp:\n", 202 | " print (item)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "metadata": {}, 208 | "source": [ 209 | "Conseil google: generator comprehension !\n", 210 | "\n", 211 | "# Beau boulot !" 212 | ] 213 | } 214 | ], 215 | "metadata": { 216 | "anaconda-cloud": {}, 217 | "kernelspec": { 218 | "display_name": "Python 3", 219 | "language": "python", 220 | "name": "python3" 221 | }, 222 | "language_info": { 223 | "codemirror_mode": { 224 | "name": "ipython", 225 | "version": 3 226 | }, 227 | "file_extension": ".py", 228 | "mimetype": "text/x-python", 229 | "name": "python", 230 | "nbconvert_exporter": "python", 231 | "pygments_lexer": "ipython3", 232 | "version": "3.6.8" 233 | } 234 | }, 235 | "nbformat": 4, 236 | "nbformat_minor": 1 237 | } 238 | -------------------------------------------------------------------------------- /11-Itérateurs et Générateurs/Devoir sur les iterateurs et les générateurs.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Devoir sur les iterateurs et les générateurs \n", 8 | "\n", 9 | "### 1er problème\n", 10 | "\n", 11 | "Créer un générateur qui génère les carrés de nombres jusqu'à un certain nombre N." 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 2, 17 | "metadata": { 18 | "collapsed": true 19 | }, 20 | "outputs": [], 21 | "source": [ 22 | "def gencarres(N):\n", 23 | " pass" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 3, 29 | "metadata": { 30 | "collapsed": false 31 | }, 32 | "outputs": [ 33 | { 34 | "ename": "TypeError", 35 | "evalue": "'NoneType' object is not iterable", 36 | "output_type": "error", 37 | "traceback": [ 38 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 39 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 40 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mgencarres\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 41 | "\u001b[0;31mTypeError\u001b[0m: 'NoneType' object is not iterable" 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "for x in gencarres(10):\n", 47 | " print (x)" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "### 2ième problème\n", 55 | "\n", 56 | "Créez un générateur qui donne «n» nombres aléatoires entre un nombre de départ et un nombre d'arrivée (qui sont les pramètres d'entrée).\n", 57 | "Remarque: utilisez la bibliothèque random.\n", 58 | "\n", 59 | "Par exemple:" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 6, 65 | "metadata": { 66 | "collapsed": false 67 | }, 68 | "outputs": [ 69 | { 70 | "data": { 71 | "text/plain": [ 72 | "6" 73 | ] 74 | }, 75 | "execution_count": 6, 76 | "metadata": {}, 77 | "output_type": "execute_result" 78 | } 79 | ], 80 | "source": [ 81 | "import random\n", 82 | "\n", 83 | "random.randint(1,10)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 7, 89 | "metadata": { 90 | "collapsed": true 91 | }, 92 | "outputs": [], 93 | "source": [ 94 | "def rand_num(départ,arrivée,n):\n", 95 | " pass" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 9, 101 | "metadata": { 102 | "collapsed": false 103 | }, 104 | "outputs": [ 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "6\n", 110 | "7\n", 111 | "6\n", 112 | "9\n", 113 | "9\n", 114 | "4\n", 115 | "3\n", 116 | "7\n", 117 | "8\n", 118 | "1\n", 119 | "6\n", 120 | "1\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "for num in numéro_aléatoire(1,10,12):\n", 126 | " print (num)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "### 3ième problème\n", 134 | "\n", 135 | "Utilisez la fonction iter () pour convertir la chaîne ci-dessous" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 1, 141 | "metadata": { 142 | "collapsed": false 143 | }, 144 | "outputs": [], 145 | "source": [ 146 | "s = 'bonjour'\n", 147 | "\n", 148 | "# le code ici" 149 | ] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "metadata": {}, 154 | "source": [ 155 | "### 4ième problème\n", 156 | "\n", 157 | "Expliquez un cas d'utilisation pour un générateur en utilisant une déclaration yield plutôt que d'utiliser une fonction normale avec une instruction de retour." 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": {}, 168 | "source": [ 169 | "### Crédits supplémentaires !\n", 170 | "Pouvez-vous expliquer ce que *gencomp* est dans le code ci-dessous?\n", 171 | "(Note: Nous n'avons jamais couvert cela en cours ! Vous devrez faire quelques appels à Google et Stack Overflow !)" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 4, 177 | "metadata": { 178 | "collapsed": false 179 | }, 180 | "outputs": [ 181 | { 182 | "name": "stdout", 183 | "output_type": "stream", 184 | "text": [ 185 | "4\n", 186 | "5\n" 187 | ] 188 | } 189 | ], 190 | "source": [ 191 | "ma_liste = [1,2,3,4,5]\n", 192 | "\n", 193 | "gencomp = (item for item in ma_liste if item > 3)\n", 194 | "\n", 195 | "for item in gencomp:\n", 196 | " print (item)" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": {}, 202 | "source": [ 203 | "Conseil google: generator comprehension !\n", 204 | "\n", 205 | "# Beau boulot !" 206 | ] 207 | } 208 | ], 209 | "metadata": { 210 | "anaconda-cloud": {}, 211 | "kernelspec": { 212 | "display_name": "Python 3", 213 | "language": "python", 214 | "name": "python3" 215 | }, 216 | "language_info": { 217 | "codemirror_mode": { 218 | "name": "ipython", 219 | "version": 3 220 | }, 221 | "file_extension": ".py", 222 | "mimetype": "text/x-python", 223 | "name": "python", 224 | "nbconvert_exporter": "python", 225 | "pygments_lexer": "ipython3", 226 | "version": "3.6.0" 227 | } 228 | }, 229 | "nbformat": 4, 230 | "nbformat_minor": 0 231 | } 232 | -------------------------------------------------------------------------------- /12-Modules Python avancés/04-Python Debugger (pdb).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# Le déboggueur Python\n", 22 | "# pdb\n", 23 | "\n", 24 | "Le moyen le plus simple de débugger son code est d'ajouter des fonctions `print` aux endroits \"critiques\". Un moyen beaucoup plus efficace de faire cela est d'utiliser le deboggueur interne de Python : `pdb`. Le module pdb met en oeuvre un environnement interactif de déboggage/debugging pour les programmes Python. Il contient des fonctionnalités pour mettre un programme en pause, inspecter les valeurs des variables, et controler l'exécution du programme par étapes, de manière à ce que vous puissiez comprendre comment se comporte votre code et trouver l'erreur dans sa logique.\n", 25 | "\n", 26 | "C'est un peu difficile à montrer, parce qu'il faut créer une erreur de programmation qui ne soit pas simpliste, mais nous allons tout de même pouvoir le mettre en oeuvre sur un exemple et montrer toute la puissance du module `pdb`.\n", 27 | "\n", 28 | "## Note\n", 29 | "*C'est plutôt totalement inhabituel, voire incongru d'utiliser pdb dans un Notebook Jupyter, qui nous sert ici de support pédagogique.*\n", 30 | "\n", 31 | "___\n", 32 | "Voici le programme et son erreur, essayer d'additionner une liste à un entier." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 1, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "5\n" 45 | ] 46 | }, 47 | { 48 | "ename": "TypeError", 49 | "evalue": "unsupported operand type(s) for +: 'int' and 'list'", 50 | "output_type": "error", 51 | "traceback": [ 52 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 53 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 54 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mresultat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mz\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mresultat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mresult2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mresultat2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 55 | "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'list'" 56 | ] 57 | } 58 | ], 59 | "source": [ 60 | "x = [1,3,4]\n", 61 | "y = 2\n", 62 | "z = 3\n", 63 | "\n", 64 | "resultat = y + z\n", 65 | "print (resultat)\n", 66 | "result2 = y+x\n", 67 | "print (resultat2)" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "Surprise ! Nous avons une erreur ?\n", 75 | "\n", 76 | "Nous allons utiliser set_trace() du module pdb. Cela va nous permettre de mettre le code en pause et regarder ce qui ne va pas." 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "5\n", 89 | "--Return--\n", 90 | "> (11)()->None\n", 91 | "-> pdb.set_trace()\n" 92 | ] 93 | } 94 | ], 95 | "source": [ 96 | "import pdb\n", 97 | "\n", 98 | "x = [1,3,4]\n", 99 | "y = 2\n", 100 | "z = 3\n", 101 | "\n", 102 | "resultat = y + z\n", 103 | "print(resultat)\n", 104 | "\n", 105 | "# Démarrer la trace avec pdb\n", 106 | "pdb.set_trace()\n", 107 | "\n", 108 | "resultat2 = y+x\n", 109 | "print(resultat2)" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "Parfait !\n", 117 | "\n", 118 | "Nous pouvons vérifier le contenu des différentes variables et identifier la ou les erreurs. \n", 119 | "Vous pouvez utiliser 'q' pour quitter le déboggueur." 120 | ] 121 | } 122 | ], 123 | "metadata": { 124 | "kernelspec": { 125 | "display_name": "Python 3", 126 | "language": "python", 127 | "name": "python3" 128 | }, 129 | "language_info": { 130 | "codemirror_mode": { 131 | "name": "ipython", 132 | "version": 3 133 | }, 134 | "file_extension": ".py", 135 | "mimetype": "text/x-python", 136 | "name": "python", 137 | "nbconvert_exporter": "python", 138 | "pygments_lexer": "ipython3", 139 | "version": "3.7.7" 140 | } 141 | }, 142 | "nbformat": 4, 143 | "nbformat_minor": 1 144 | } 145 | -------------------------------------------------------------------------------- /12-Modules Python avancés/08-Exercices sur les modules Python avancés/07-Advanced-Modules-Exercise-Puzzle.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | "\n", 10 | "___\n", 11 | "
Content Copyright by Pierian Data
" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "# Advanced Modules Exercise Puzzle\n", 19 | "\n", 20 | "It's time to test your new skills, this puzzle project will combine multiple skills sets, including unzipping files with Python, using os module to automatically search through lots of files.\n", 21 | "\n", 22 | "## Your Goal\n", 23 | "\n", 24 | "This is a puzzle, so we don't want to give you too much guidance and instead have you figure out things on your own.\n", 25 | "\n", 26 | "There is a .zip file called 'unzip_me_for_instructions.zip', unzip it, open the .txt file with Python, read the instructions and see if you can figure out what you need to do!\n", 27 | "\n", 28 | "**If you get stuck or don't know where to start, here is a [guide/hints](https://docs.google.com/document/d/1JxydUr4n4fSR0EwwuwT-aHia-yPK6r-oTBuVT2sqheo/edit?usp=sharing)**" 29 | ] 30 | } 31 | ], 32 | "metadata": { 33 | "anaconda-cloud": {}, 34 | "kernelspec": { 35 | "display_name": "Python 3", 36 | "language": "python", 37 | "name": "python3" 38 | }, 39 | "language_info": { 40 | "codemirror_mode": { 41 | "name": "ipython", 42 | "version": 3 43 | }, 44 | "file_extension": ".py", 45 | "mimetype": "text/x-python", 46 | "name": "python", 47 | "nbconvert_exporter": "python", 48 | "pygments_lexer": "ipython3", 49 | "version": "3.6.6" 50 | } 51 | }, 52 | "nbformat": 4, 53 | "nbformat_minor": 2 54 | } 55 | -------------------------------------------------------------------------------- /12-Modules Python avancés/08-Exercices sur les modules Python avancés/08-Advanced-Modules-Exercise-Solutions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | "\n", 10 | "___\n", 11 | "
Content Copyright by Pierian Data
" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "# Advanced Modules Exercise Solutions\n", 19 | "\n", 20 | "It's time to test your new skills, this puzzle project will combine multiple skills sets, including unzipping files with Python, using os module to automatically search through lots of files.\n", 21 | "\n", 22 | "## Your Goal\n", 23 | "\n", 24 | "This is a puzzle, so we don't want to give you too much guidance and instead have you figure out things on your own.\n", 25 | "\n", 26 | "There is a .zip file called 'unzip_me_for_instructions.zip', unzip it, open the .txt file with Python, read the instructions and see if you can figure out what you need to do!\n", 27 | "\n", 28 | "**If you get stuck or don't know where to start, here is a [guide/hints](https://docs.google.com/document/d/1JxydUr4n4fSR0EwwuwT-aHia-yPK6r-oTBuVT2sqheo/edit?usp=sharing)**" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Step 1: Unzipping the File\n", 36 | "\n", 37 | "We can easily use the shutil library to extract and unzip the contents of the .zip file" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 2, 43 | "metadata": { 44 | "collapsed": true 45 | }, 46 | "outputs": [], 47 | "source": [ 48 | "import shutil" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 3, 54 | "metadata": { 55 | "collapsed": true 56 | }, 57 | "outputs": [], 58 | "source": [ 59 | "shutil.unpack_archive('unzip_me_for_instructions.zip','','zip')" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": {}, 65 | "source": [ 66 | "## Step 2: Read the instructions file\n", 67 | "\n", 68 | "Let's figure out what we need to do, open the instructions.txt file." 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 7, 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "name": "stdout", 78 | "output_type": "stream", 79 | "text": [ 80 | "Good work on unzipping the file!\n", 81 | "You should now see 5 folders, each with a lot of random .txt files.\n", 82 | "Within one of these text files is a telephone number formated ###-###-#### \n", 83 | "Use the Python os module and regular expressions to iterate through each file, open it, and search for a telephone number.\n", 84 | "Good luck!\n" 85 | ] 86 | } 87 | ], 88 | "source": [ 89 | "with open('extracted_content/Instructions.txt') as f:\n", 90 | " content = f.read()\n", 91 | " print(content)" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "## Step 3: Regular Expression to Find the Link\n", 99 | "\n", 100 | "There are many approaches to take here, but since we know we are looking for a phone number, there should be a digits in the form ###-###-####, so we can easily create a regex expression for this and test it. Once its tested and working, we can figure out how to run it through all the txt documents." 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 9, 106 | "metadata": { 107 | "collapsed": true 108 | }, 109 | "outputs": [], 110 | "source": [ 111 | "import re" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 10, 117 | "metadata": { 118 | "collapsed": true 119 | }, 120 | "outputs": [], 121 | "source": [ 122 | "pattern = r'\\d{3}-\\d{3}-\\d{4}'" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 11, 128 | "metadata": { 129 | "collapsed": true 130 | }, 131 | "outputs": [], 132 | "source": [ 133 | "test_string = \"here is a random number 1231231234 , here is phone number formatted 123-123-1234\"" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 14, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "data": { 143 | "text/plain": [ 144 | "['123-123-1234']" 145 | ] 146 | }, 147 | "execution_count": 14, 148 | "metadata": {}, 149 | "output_type": "execute_result" 150 | } 151 | ], 152 | "source": [ 153 | "re.findall(pattern,test_string)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "## Step 4: Create a function for regex\n", 161 | "\n", 162 | "Let's put this inside a function that applies it to the contents of a .txt file, this way we can apply this function to all the txt files in the extracted_content folder." 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 15, 168 | "metadata": { 169 | "collapsed": true 170 | }, 171 | "outputs": [], 172 | "source": [ 173 | "def search(file,pattern= r'\\d{3}-\\d{3}-\\d{4}'):\n", 174 | " f = open(file,'r')\n", 175 | " text = f.read()\n", 176 | " \n", 177 | " if re.search(pattern,text):\n", 178 | " return re.search(pattern,text)\n", 179 | " else:\n", 180 | " return ''" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "## Step 5: OS Walk through the Files to Get the Link\n", 188 | "\n", 189 | "Now that we have a basic function to search through the text of the files, let's perform an os.walk through the unzipped directory to find the links hidden somewhere in one of the text files." 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 16, 195 | "metadata": { 196 | "collapsed": true 197 | }, 198 | "outputs": [], 199 | "source": [ 200 | "import os" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 17, 206 | "metadata": { 207 | "collapsed": true 208 | }, 209 | "outputs": [], 210 | "source": [ 211 | "results = []\n", 212 | "for folder , sub_folders , files in os.walk(os.getcwd()+\"\\\\extracted_content\"):\n", 213 | " \n", 214 | " for f in files:\n", 215 | " full_path = folder+'\\\\'+f\n", 216 | " \n", 217 | " results.append(search(full_path)) " 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 18, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "name": "stdout", 227 | "output_type": "stream", 228 | "text": [ 229 | "719-266-2837\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "for r in results:\n", 235 | " if r != '':\n", 236 | " print(r.group())" 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "metadata": {}, 242 | "source": [ 243 | "___\n", 244 | "Excellent work! More information on this phone number:\n", 245 | "* https://www.npr.org/2011/12/21/144069758/callin-oates-the-hotline-you-dont-need-but-might-call-anyway\n", 246 | "* https://twitter.com/CallinOates" 247 | ] 248 | } 249 | ], 250 | "metadata": { 251 | "anaconda-cloud": {}, 252 | "kernelspec": { 253 | "display_name": "Python 3", 254 | "language": "python", 255 | "name": "python3" 256 | }, 257 | "language_info": { 258 | "codemirror_mode": { 259 | "name": "ipython", 260 | "version": 3 261 | }, 262 | "file_extension": ".py", 263 | "mimetype": "text/x-python", 264 | "name": "python", 265 | "nbconvert_exporter": "python", 266 | "pygments_lexer": "ipython3", 267 | "version": "3.6.6" 268 | } 269 | }, 270 | "nbformat": 4, 271 | "nbformat_minor": 2 272 | } 273 | -------------------------------------------------------------------------------- /12-Modules Python avancés/08-Exercices sur les modules Python avancés/unzip_me_for_instructions.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/12-Modules Python avancés/08-Exercices sur les modules Python avancés/unzip_me_for_instructions.zip -------------------------------------------------------------------------------- /12-Modules Python avancés/Exemple_Dossier_Racine/Exemple-Haut-un/Document-Niveau-Moyen.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/12-Modules Python avancés/Exemple_Dossier_Racine/Exemple-Haut-un/Document-Niveau-Moyen.txt -------------------------------------------------------------------------------- /12-Modules Python avancés/Exemple_Dossier_Racine/Exemple-Haut-un/Niveau-Moyen-Deux/Text-Niveau-Profond.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/12-Modules Python avancés/Exemple_Dossier_Racine/Exemple-Haut-un/Niveau-Moyen-Deux/Text-Niveau-Profond.txt -------------------------------------------------------------------------------- /12-Modules Python avancés/Exemple_Dossier_Racine/Exemple-Haut-un/Niveau-Moyen-Un/Un_texte.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/12-Modules Python avancés/Exemple_Dossier_Racine/Exemple-Haut-un/Niveau-Moyen-Un/Un_texte.txt -------------------------------------------------------------------------------- /12-Modules Python avancés/Exemple_Dossier_Racine/Exemple-Haut.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/12-Modules Python avancés/Exemple_Dossier_Racine/Exemple-Haut.txt -------------------------------------------------------------------------------- /13-Web Scraping/mon_nouveau_fichier_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/13-Web Scraping/mon_nouveau_fichier_image.jpg -------------------------------------------------------------------------------- /14-Travailler avec des images/01-Exercice sur les images.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# Exercice avec des Images\n", 22 | "\n", 23 | "Dans le dossier courant \"14-Travailler avec des images\" vous trouverez 2 images pour réaliser cet exercice :\n", 24 | "\n", 25 | "* matrice_de_mots.png\n", 26 | "* masque.png\n", 27 | "\n", 28 | "L'image png \"matrice_de_mots\" contient un tableau de mots qui cache un message secret.\n", 29 | "\n", 30 | "Votre tâche sera d'utiliser l'image \"masque.png\" pour révéler le message secret caché dans \"matrice_de_mots.png\". N'oubliez pas, vous pourriez avoir des modifications à faire sur \"masque.png\" pour que cela fonctionne.\n", 31 | "\n", 32 | "C'est tout ce que je vous dit, pour vous laisser chercher et trouver par vos propres moyens. C'est un exercice totalement ouvert, vous devrez donc vous débrouiller seuls comme dans une situation réelle. Mais pas d'inquiétude, si vous êtes vraiment totalement bloqués, vous pourrez toujours consulter la solution pas à pas en vidéo ou le notebook qui la contient pour voir comment faire.\n", 33 | "\n", 34 | "Bonne chance !\n" 35 | ] 36 | } 37 | ], 38 | "metadata": { 39 | "kernelspec": { 40 | "display_name": "Python 3", 41 | "language": "python", 42 | "name": "python3" 43 | }, 44 | "language_info": { 45 | "codemirror_mode": { 46 | "name": "ipython", 47 | "version": 3 48 | }, 49 | "file_extension": ".py", 50 | "mimetype": "text/x-python", 51 | "name": "python", 52 | "nbconvert_exporter": "python", 53 | "pygments_lexer": "ipython3", 54 | "version": "3.8.3" 55 | } 56 | }, 57 | "nbformat": 4, 58 | "nbformat_minor": 2 59 | } 60 | -------------------------------------------------------------------------------- /14-Travailler avec des images/blue_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/14-Travailler avec des images/blue_color.png -------------------------------------------------------------------------------- /14-Travailler avec des images/crayons.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/14-Travailler avec des images/crayons.jpg -------------------------------------------------------------------------------- /14-Travailler avec des images/exemple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/14-Travailler avec des images/exemple.jpg -------------------------------------------------------------------------------- /14-Travailler avec des images/masque.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/14-Travailler avec des images/masque.png -------------------------------------------------------------------------------- /14-Travailler avec des images/matrice_de_mots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/14-Travailler avec des images/matrice_de_mots.png -------------------------------------------------------------------------------- /14-Travailler avec des images/mauve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/14-Travailler avec des images/mauve.png -------------------------------------------------------------------------------- /14-Travailler avec des images/rouge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/14-Travailler avec des images/rouge.jpg -------------------------------------------------------------------------------- /14-Travailler avec des images/word_matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/14-Travailler avec des images/word_matrix.png -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/02-PDFs-Spreadsheets-Puzzle.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# PDFs and Spreadsheets Puzzle Exercise\n", 22 | "\n", 23 | "Let's test your skills, the files needed for this puzzle exercise\n", 24 | "\n", 25 | "You will need to work with two files for this exercise and solve the following tasks:\n", 26 | "\n", 27 | "* Task One: Use Python to extract the Google Drive link from the .csv file. (Hint: Its along the diagonal from top left to bottom right).\n", 28 | "* Task Two: Download the PDF from the Google Drive link (we already downloaded it for you just in case you can't download from Google Drive) and find the phone number that is in the document. Note: There are different ways of formatting a phone number!" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Task One: Grab the Google Drive Link from .csv File" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": { 42 | "collapsed": true 43 | }, 44 | "outputs": [], 45 | "source": [] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 14, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "data": { 54 | "text/plain": [ 55 | "'https://drive.google.com/open?id=1G6SEgg018UB4_4xsAJJ5TdzrhmXipr4Q'" 56 | ] 57 | }, 58 | "execution_count": 14, 59 | "metadata": {}, 60 | "output_type": "execute_result" 61 | } 62 | ], 63 | "source": [ 64 | "# THe correct result is shown below, if you can't download from Google Drive, \n", 65 | "# we added the PDF file to the Exercise_Files folder already" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "## Task Two: Download the PDF from the Google Drive link and find the phone number that is in the document. " 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 1, 78 | "metadata": { 79 | "collapsed": true 80 | }, 81 | "outputs": [], 82 | "source": [ 83 | "# You should get this phone number\n", 84 | "# 505 503 4455" 85 | ] 86 | } 87 | ], 88 | "metadata": { 89 | "anaconda-cloud": {}, 90 | "kernelspec": { 91 | "display_name": "Python 3", 92 | "language": "python", 93 | "name": "python3" 94 | }, 95 | "language_info": { 96 | "codemirror_mode": { 97 | "name": "ipython", 98 | "version": 3 99 | }, 100 | "file_extension": ".py", 101 | "mimetype": "text/x-python", 102 | "name": "python", 103 | "nbconvert_exporter": "python", 104 | "pygments_lexer": "ipython3", 105 | "version": "3.8.3" 106 | } 107 | }, 108 | "nbformat": 4, 109 | "nbformat_minor": 2 110 | } 111 | -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/Exercise_Files/Find_the_Phone_Number.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/15-PDFs et tableaux de données/Exercise_Files/Find_the_Phone_Number.pdf -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/Some_BrandNew_Doc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/15-PDFs et tableaux de données/Some_BrandNew_Doc.pdf -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/Some_New_Doc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/15-PDFs et tableaux de données/Some_New_Doc.pdf -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/Some_new_file.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/15-PDFs et tableaux de données/Some_new_file.pdf -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/Working_Business_Proposal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/15-PDFs et tableaux de données/Working_Business_Proposal.pdf -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/fichier_à_sauver.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/15-PDFs et tableaux de données/fichier_à_sauver.csv -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/makeup_new.csv: -------------------------------------------------------------------------------- 1 | col1,col2,col3 2 | 1,2,3 3 | 4,5,6 4 | 7,8,9 5 | -------------------------------------------------------------------------------- /15-PDFs et tableaux de données/to_save_file.csv: -------------------------------------------------------------------------------- 1 | a,b,c 2 | 1,2,3 3 | 4,5,6 4 | new,new,new 5 | -------------------------------------------------------------------------------- /16-Envoi d'emails avec Python/02-Exercise-Ideas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# Python Email Exercise Ideas\n", 22 | "\n", 23 | "Since we can't really assess any code that would involve your personal email address, here are some ideas for you to test your new skills. Please keep in mind, we can not assess these." 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "\n", 31 | "## Ideas\n", 32 | "\n", 33 | "* Daily Automatic Email Reminder for your Tasks\n", 34 | "* Webscrape some statistics from a website automatically each day and email them to yourself\n", 35 | "* Automatically email daily/weekly/monthly reports at your work\n", 36 | "* Have end of day messages to your friends and family be sent out at random to spread joy\n", 37 | "* Be creative! Mix together any of the skills you've learned so far with email :)" 38 | ] 39 | } 40 | ], 41 | "metadata": { 42 | "kernelspec": { 43 | "display_name": "Python 3", 44 | "language": "python", 45 | "name": "python3" 46 | }, 47 | "language_info": { 48 | "codemirror_mode": { 49 | "name": "ipython", 50 | "version": 3 51 | }, 52 | "file_extension": ".py", 53 | "mimetype": "text/x-python", 54 | "name": "python", 55 | "nbconvert_exporter": "python", 56 | "pygments_lexer": "ipython3", 57 | "version": "3.8.3" 58 | } 59 | }, 60 | "nbformat": 4, 61 | "nbformat_minor": 2 62 | } 63 | -------------------------------------------------------------------------------- /17-Objets et structures de données Python avancés/01-Advanced Numbers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": { 20 | "collapsed": true 21 | }, 22 | "source": [ 23 | "# Advanced Numbers\n", 24 | "In this lecture we will learn about a few more representations of numbers in Python." 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## Hexadecimal\n", 32 | "\n", 33 | "Using the function hex() you can convert numbers into a [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) format:" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 1, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "'0xf6'" 45 | ] 46 | }, 47 | "execution_count": 1, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "hex(246)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 2, 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "data": { 63 | "text/plain": [ 64 | "'0x200'" 65 | ] 66 | }, 67 | "execution_count": 2, 68 | "metadata": {}, 69 | "output_type": "execute_result" 70 | } 71 | ], 72 | "source": [ 73 | "hex(512)" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "## Binary \n", 81 | "Using the function bin() you can convert numbers into their [binary](https://en.wikipedia.org/wiki/Binary_number) format." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 3, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "'0b10011010010'" 93 | ] 94 | }, 95 | "execution_count": 3, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "bin(1234)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 4, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "'0b10000000'" 113 | ] 114 | }, 115 | "execution_count": 4, 116 | "metadata": {}, 117 | "output_type": "execute_result" 118 | } 119 | ], 120 | "source": [ 121 | "bin(128)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 5, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "data": { 131 | "text/plain": [ 132 | "'0b1000000000'" 133 | ] 134 | }, 135 | "execution_count": 5, 136 | "metadata": {}, 137 | "output_type": "execute_result" 138 | } 139 | ], 140 | "source": [ 141 | "bin(512)" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": {}, 147 | "source": [ 148 | "## Exponentials\n", 149 | "The function pow() takes two arguments, equivalent to ```x^y```. With three arguments it is equivalent to ```(x^y)%z```, but may be more efficient for long integers." 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 6, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "data": { 159 | "text/plain": [ 160 | "81" 161 | ] 162 | }, 163 | "execution_count": 6, 164 | "metadata": {}, 165 | "output_type": "execute_result" 166 | } 167 | ], 168 | "source": [ 169 | "pow(3,4)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 7, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "data": { 179 | "text/plain": [ 180 | "1" 181 | ] 182 | }, 183 | "execution_count": 7, 184 | "metadata": {}, 185 | "output_type": "execute_result" 186 | } 187 | ], 188 | "source": [ 189 | "pow(3,4,5)" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "## Absolute Value\n", 197 | "The function abs() returns the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a complex number, its magnitude is returned.\n" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 8, 203 | "metadata": {}, 204 | "outputs": [ 205 | { 206 | "data": { 207 | "text/plain": [ 208 | "3.14" 209 | ] 210 | }, 211 | "execution_count": 8, 212 | "metadata": {}, 213 | "output_type": "execute_result" 214 | } 215 | ], 216 | "source": [ 217 | "abs(-3.14)" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 9, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "data": { 227 | "text/plain": [ 228 | "3" 229 | ] 230 | }, 231 | "execution_count": 9, 232 | "metadata": {}, 233 | "output_type": "execute_result" 234 | } 235 | ], 236 | "source": [ 237 | "abs(3)" 238 | ] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "metadata": {}, 243 | "source": [ 244 | "## Round\n", 245 | "The function round() will round a number to a given precision in decimal digits (default 0 digits). It does not convert integers to floats." 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 10, 251 | "metadata": {}, 252 | "outputs": [ 253 | { 254 | "data": { 255 | "text/plain": [ 256 | "3" 257 | ] 258 | }, 259 | "execution_count": 10, 260 | "metadata": {}, 261 | "output_type": "execute_result" 262 | } 263 | ], 264 | "source": [ 265 | "round(3,2)" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 11, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "data": { 275 | "text/plain": [ 276 | "400" 277 | ] 278 | }, 279 | "execution_count": 11, 280 | "metadata": {}, 281 | "output_type": "execute_result" 282 | } 283 | ], 284 | "source": [ 285 | "round(395,-2)" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 12, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "data": { 295 | "text/plain": [ 296 | "3.14" 297 | ] 298 | }, 299 | "execution_count": 12, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "round(3.1415926535,2)" 306 | ] 307 | }, 308 | { 309 | "cell_type": "markdown", 310 | "metadata": {}, 311 | "source": [ 312 | "Python has a built-in math library that is also useful to play around with in case you are ever in need of some mathematical operations. Explore the documentation [here](https://docs.python.org/3/library/math.html)!" 313 | ] 314 | } 315 | ], 316 | "metadata": { 317 | "kernelspec": { 318 | "display_name": "Python 3", 319 | "language": "python", 320 | "name": "python3" 321 | }, 322 | "language_info": { 323 | "codemirror_mode": { 324 | "name": "ipython", 325 | "version": 3 326 | }, 327 | "file_extension": ".py", 328 | "mimetype": "text/x-python", 329 | "name": "python", 330 | "nbconvert_exporter": "python", 331 | "pygments_lexer": "ipython3", 332 | "version": "3.8.3" 333 | } 334 | }, 335 | "nbformat": 4, 336 | "nbformat_minor": 1 337 | } 338 | -------------------------------------------------------------------------------- /17-Objets et structures de données Python avancés/04-Advanced Dictionaries.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# Advanced Dictionaries\n", 22 | "Unlike some of the other Data Structures we've worked with, most of the really useful methods available to us in Dictionaries have already been explored throughout this course. Here we will touch on just a few more for good measure:" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "## Dictionary Comprehensions\n", 30 | "\n", 31 | "Just like List Comprehensions, Dictionary Data Types also support their own version of comprehension for quick creation. It is not as commonly used as List Comprehensions, but the syntax is:" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 1, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "data": { 41 | "text/plain": [ 42 | "{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}" 43 | ] 44 | }, 45 | "execution_count": 1, 46 | "metadata": {}, 47 | "output_type": "execute_result" 48 | } 49 | ], 50 | "source": [ 51 | "{x:x**2 for x in range(10)}" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "One of the reasons it is not as common is the difficulty in structuring key names that are not based off the values." 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "## Iteration over keys, values, and items\n", 66 | "Dictionaries can be iterated over using the keys(), values() and items() methods. For example:" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 2, 72 | "metadata": {}, 73 | "outputs": [], 74 | "source": [ 75 | "d = {'k1':1,'k2':2}" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 3, 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "k1\n", 88 | "k2\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "for k in d.keys():\n", 94 | " print(k)" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "1\n", 107 | "2\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "for v in d.values():\n", 113 | " print(v)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 5, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "('k1', 1)\n", 126 | "('k2', 2)\n" 127 | ] 128 | } 129 | ], 130 | "source": [ 131 | "for item in d.items():\n", 132 | " print(item)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "markdown", 137 | "metadata": {}, 138 | "source": [ 139 | "# Viewing keys, values and items\n", 140 | "By themselves the keys(), values() and items() methods return a dictionary *view object*. This is not a separate list of items. Instead, the view is always tied to the original dictionary." 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 6, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "data": { 150 | "text/plain": [ 151 | "dict_keys(['k1', 'k2'])" 152 | ] 153 | }, 154 | "execution_count": 6, 155 | "metadata": {}, 156 | "output_type": "execute_result" 157 | } 158 | ], 159 | "source": [ 160 | "key_view = d.keys()\n", 161 | "\n", 162 | "key_view" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 7, 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "{'k1': 1, 'k2': 2, 'k3': 3}" 174 | ] 175 | }, 176 | "execution_count": 7, 177 | "metadata": {}, 178 | "output_type": "execute_result" 179 | } 180 | ], 181 | "source": [ 182 | "d['k3'] = 3\n", 183 | "\n", 184 | "d" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 8, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "data": { 194 | "text/plain": [ 195 | "dict_keys(['k1', 'k2', 'k3'])" 196 | ] 197 | }, 198 | "execution_count": 8, 199 | "metadata": {}, 200 | "output_type": "execute_result" 201 | } 202 | ], 203 | "source": [ 204 | "key_view" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "Great! You should now feel very comfortable using the variety of methods available to you in Dictionaries!" 212 | ] 213 | } 214 | ], 215 | "metadata": { 216 | "kernelspec": { 217 | "display_name": "Python 3", 218 | "language": "python", 219 | "name": "python3" 220 | }, 221 | "language_info": { 222 | "codemirror_mode": { 223 | "name": "ipython", 224 | "version": 3 225 | }, 226 | "file_extension": ".py", 227 | "mimetype": "text/x-python", 228 | "name": "python", 229 | "nbconvert_exporter": "python", 230 | "pygments_lexer": "ipython3", 231 | "version": "3.8.3" 232 | } 233 | }, 234 | "nbformat": 4, 235 | "nbformat_minor": 1 236 | } 237 | -------------------------------------------------------------------------------- /17-Objets et structures de données Python avancés/06-Advanced Python Objects Test.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# Advanced Python Objects Test" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "## Advanced Numbers\n", 29 | "\n", 30 | "**Problem 1: Convert 1024 to binary and hexadecimal representation**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "**Problem 2: Round 5.23222 to two decimal places**" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## Advanced Strings\n", 59 | "**Problem 3: Check if every letter in the string s is lower case**" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": null, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "s = 'hello how are you Mary, are you feeling okay?'\n", 69 | "\n" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "**Problem 4: How many times does the letter 'w' show up in the string below?**" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "s = 'twywywtwywbwhsjhwuwshshwuwwwjdjdid'\n" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "## Advanced Sets\n", 93 | "**Problem 5: Find the elements in set1 that are not in set2:**" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [ 102 | "set1 = {2,3,1,5,6,8}\n", 103 | "set2 = {3,1,7,5,6,8}\n", 104 | "\n" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": {}, 110 | "source": [ 111 | "**Problem 6: Find all elements that are in either set:**" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "metadata": {}, 124 | "source": [ 125 | "## Advanced Dictionaries\n", 126 | "\n", 127 | "**Problem 7: Create this dictionary:\n", 128 | "{0: 0, 1: 1, 2: 8, 3: 27, 4: 64}\n", 129 | " using a dictionary comprehension.**" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [] 138 | }, 139 | { 140 | "cell_type": "markdown", 141 | "metadata": {}, 142 | "source": [ 143 | "## Advanced Lists\n", 144 | "\n", 145 | "**Problem 8: Reverse the list below:**" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [ 154 | "list1 = [1,2,3,4]\n" 155 | ] 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "metadata": {}, 160 | "source": [ 161 | "**Problem 9: Sort the list below:**" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": null, 167 | "metadata": {}, 168 | "outputs": [], 169 | "source": [ 170 | "list2 = [3,4,2,5,1]\n" 171 | ] 172 | }, 173 | { 174 | "cell_type": "markdown", 175 | "metadata": {}, 176 | "source": [ 177 | "# Great Job!" 178 | ] 179 | } 180 | ], 181 | "metadata": { 182 | "kernelspec": { 183 | "display_name": "Python 3", 184 | "language": "python", 185 | "name": "python3" 186 | }, 187 | "language_info": { 188 | "codemirror_mode": { 189 | "name": "ipython", 190 | "version": 3 191 | }, 192 | "file_extension": ".py", 193 | "mimetype": "text/x-python", 194 | "name": "python", 195 | "nbconvert_exporter": "python", 196 | "pygments_lexer": "ipython3", 197 | "version": "3.8.3" 198 | } 199 | }, 200 | "nbformat": 4, 201 | "nbformat_minor": 1 202 | } 203 | -------------------------------------------------------------------------------- /17-Objets et structures de données Python avancés/07-Advanced Python Objects Test - Solutions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# Advanced Python Objects Test" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "## Advanced Numbers\n", 29 | "\n", 30 | "**Problem 1: Convert 1024 to binary and hexadecimal representation**" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 1, 36 | "metadata": {}, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "0b10000000000\n", 43 | "0x400\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "print(bin(1024))\n", 49 | "print(hex(1024))" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "**Problem 2: Round 5.23222 to two decimal places**" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 2, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "5.23" 68 | ] 69 | }, 70 | "execution_count": 2, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "round(5.23222,2)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "## Advanced Strings\n", 84 | "**Problem 3: Check if every letter in the string s is lower case**" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 3, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "data": { 94 | "text/plain": [ 95 | "False" 96 | ] 97 | }, 98 | "execution_count": 3, 99 | "metadata": {}, 100 | "output_type": "execute_result" 101 | } 102 | ], 103 | "source": [ 104 | "s = 'hello how are you Mary, are you feeling okay?'\n", 105 | "\n", 106 | "s.islower()" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "**Problem 4: How many times does the letter 'w' show up in the string below?**" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 4, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/plain": [ 124 | "12" 125 | ] 126 | }, 127 | "execution_count": 4, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "s = 'twywywtwywbwhsjhwuwshshwuwwwjdjdid'\n", 134 | "s.count('w')" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "## Advanced \n", 142 | "**Problem 5: Find the elements in set1 that are not in set2:**" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 5, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "data": { 152 | "text/plain": [ 153 | "{2}" 154 | ] 155 | }, 156 | "execution_count": 5, 157 | "metadata": {}, 158 | "output_type": "execute_result" 159 | } 160 | ], 161 | "source": [ 162 | "set1 = {2,3,1,5,6,8}\n", 163 | "set2 = {3,1,7,5,6,8}\n", 164 | "\n", 165 | "set1.difference(set2)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": {}, 171 | "source": [ 172 | "**Problem 6: Find all elements that are in either set:**" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 6, 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "data": { 182 | "text/plain": [ 183 | "{1, 2, 3, 5, 6, 7, 8}" 184 | ] 185 | }, 186 | "execution_count": 6, 187 | "metadata": {}, 188 | "output_type": "execute_result" 189 | } 190 | ], 191 | "source": [ 192 | "set1.union(set2)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "metadata": {}, 198 | "source": [ 199 | "## Advanced Dictionaries\n", 200 | "\n", 201 | "**Problem 7: Create this dictionary:\n", 202 | "{0: 0, 1: 1, 2: 8, 3: 27, 4: 64}\n", 203 | " using a dictionary comprehension.**" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 7, 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "data": { 213 | "text/plain": [ 214 | "{0: 0, 1: 1, 2: 8, 3: 27, 4: 64}" 215 | ] 216 | }, 217 | "execution_count": 7, 218 | "metadata": {}, 219 | "output_type": "execute_result" 220 | } 221 | ], 222 | "source": [ 223 | "{x:x**3 for x in range(5)}" 224 | ] 225 | }, 226 | { 227 | "cell_type": "markdown", 228 | "metadata": {}, 229 | "source": [ 230 | "## Advanced Lists\n", 231 | "\n", 232 | "**Problem 8: Reverse the list below:**" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 8, 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "data": { 242 | "text/plain": [ 243 | "[4, 3, 2, 1]" 244 | ] 245 | }, 246 | "execution_count": 8, 247 | "metadata": {}, 248 | "output_type": "execute_result" 249 | } 250 | ], 251 | "source": [ 252 | "list1 = [1,2,3,4]\n", 253 | "\n", 254 | "list1.reverse()\n", 255 | "\n", 256 | "list1" 257 | ] 258 | }, 259 | { 260 | "cell_type": "markdown", 261 | "metadata": {}, 262 | "source": [ 263 | "**Problem 9: Sort the list below:**" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": 9, 269 | "metadata": {}, 270 | "outputs": [ 271 | { 272 | "data": { 273 | "text/plain": [ 274 | "[1, 2, 3, 4, 5]" 275 | ] 276 | }, 277 | "execution_count": 9, 278 | "metadata": {}, 279 | "output_type": "execute_result" 280 | } 281 | ], 282 | "source": [ 283 | "list2 = [3,4,2,5,1]\n", 284 | "\n", 285 | "list2.sort()\n", 286 | "\n", 287 | "list2" 288 | ] 289 | }, 290 | { 291 | "cell_type": "markdown", 292 | "metadata": {}, 293 | "source": [ 294 | "# Great Job!" 295 | ] 296 | } 297 | ], 298 | "metadata": { 299 | "kernelspec": { 300 | "display_name": "Python 3", 301 | "language": "python", 302 | "name": "python3" 303 | }, 304 | "language_info": { 305 | "codemirror_mode": { 306 | "name": "ipython", 307 | "version": 3 308 | }, 309 | "file_extension": ".py", 310 | "mimetype": "text/x-python", 311 | "name": "python", 312 | "nbconvert_exporter": "python", 313 | "pygments_lexer": "ipython3", 314 | "version": "3.8.3" 315 | } 316 | }, 317 | "nbformat": 4, 318 | "nbformat_minor": 1 319 | } 320 | -------------------------------------------------------------------------------- /19-Bonus - Introduction aux interfaces graphiques (GUI)/08-Advanced Widget Styling with Layout.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# Advanced Widget Styling with Layout\n", 22 | "\n", 23 | "This notebook expands on the **Widget Styling** lecture by describing the various HTML and CSS adjustments that can be made through the `layout` attribute." 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "## The `layout` attribute\n", 31 | "Jupyter interactive widgets have a `layout` attribute exposing a number of CSS properties that impact how widgets are laid out.\n", 32 | "\n", 33 | "### Exposed CSS properties\n", 34 | "
The following properties map to the values of the CSS properties of the same name (underscores being replaced with dashes), applied to the top DOM elements of the corresponding widget.
\n", 35 | "\n", 36 | "#### Sizes\n", 37 | "* `height`\n", 38 | "* `width`\n", 39 | "* `max_height`\n", 40 | "* `max_width`\n", 41 | "* `min_height`\n", 42 | "* `min_width`\n", 43 | "\n", 44 | "#### Display\n", 45 | "* `visibility`\n", 46 | "* `display`\n", 47 | "* `overflow`\n", 48 | "* `overflow_x`\n", 49 | "* `overflow_y`\n", 50 | "\n", 51 | "#### Box model\n", 52 | "* `border`\n", 53 | "* `margin`\n", 54 | "* `padding`\n", 55 | "\n", 56 | "#### Positioning\n", 57 | "* `top`\n", 58 | "* `left`\n", 59 | "* `bottom`\n", 60 | "* `right`\n", 61 | "\n", 62 | "#### Flexbox\n", 63 | "* `order`\n", 64 | "* `flex_flow`\n", 65 | "* `align_items`\n", 66 | "* `flex`\n", 67 | "* `align_self`\n", 68 | "* `align_content`\n", 69 | "* `justify_content`\n", 70 | "\n", 71 | "### Shorthand CSS properties\n", 72 | "\n", 73 | "You may have noticed that certain CSS properties such as `margin-[top/right/bottom/left]` seem to be missing. The same holds for `padding-[top/right/bottom/left]` etc.\n", 74 | "\n", 75 | "In fact, you can atomically specify `[top/right/bottom/left]` margins via the `margin` attribute alone by passing the string `'100px 150px 100px 80px'` for a respectively `top`, `right`, `bottom` and `left` margins of `100`, `150`, `100` and `80` pixels.\n", 76 | "\n", 77 | "Similarly, the `flex` attribute can hold values for `flex-grow`, `flex-shrink` and `flex-basis`. The `border` attribute is a shorthand property for `border-width`, `border-style (required)`, and `border-color`." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 19, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "import ipywidgets as widgets\n", 87 | "from IPython.display import display" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "# Conclusion\n", 95 | "\n", 96 | "You should now have an understanding of how to style widgets!" 97 | ] 98 | } 99 | ], 100 | "metadata": { 101 | "cell_tags": [ 102 | [ 103 | "", 104 | null 105 | ] 106 | ], 107 | "kernelspec": { 108 | "display_name": "Python 3", 109 | "language": "python", 110 | "name": "python3" 111 | }, 112 | "language_info": { 113 | "codemirror_mode": { 114 | "name": "ipython", 115 | "version": 3 116 | }, 117 | "file_extension": ".py", 118 | "mimetype": "text/x-python", 119 | "name": "python", 120 | "nbconvert_exporter": "python", 121 | "pygments_lexer": "ipython3", 122 | "version": "3.8.3" 123 | } 124 | }, 125 | "nbformat": 4, 126 | "nbformat_minor": 1 127 | } 128 | -------------------------------------------------------------------------------- /99-a positionner/06_StringIO.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "___\n", 8 | "\n", 9 | " \n", 10 | " \n", 11 | "
\n", 12 | "
\n", 13 | " \n", 14 | "
Content Copyright by Pierian Data and xDM Consulting
" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# StringIO \n", 22 | "\n", 23 | "Le module io et sa méthode StringIO permettent d'implémenter des objets qui se comportent comme des fichiers mais qui sont stockés en mémoire centrale.\n", 24 | "\n", 25 | "Ces objets peuvent être utilisés en entrée ou en sortie avec les mêmes fonctions que celles que l'on trouve pour les fichiers traditionnels.\n", 26 | "\n", 27 | "Comme d'habitude, le plus simple pour comprendre cela est de le voir avec un exemple :\n" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "import io" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "# Une chaine de caractères\n", 48 | "message = 'Voici une chaine de caractères toute simple.'" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 8, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "# StringIO va 'ouvrir' la chaine et en faire un fichier\n", 58 | "f = io.StringIO(message)" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "Nous avons créé un objet : *f* que l'on va pouvoir traiter comme s'il s'agissait d'un fichier.\n", 66 | "\n", 67 | "Par exemple :" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 9, 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "'Voici une chaine de caractères toute simple.'" 79 | ] 80 | }, 81 | "execution_count": 9, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "f.read()" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "On peut aussi écrire :" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 10, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "52" 106 | ] 107 | }, 108 | "execution_count": 10, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "f.write(\" Deuxième ligne de cet objet qui a tout d'un fichier\")" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 11, 120 | "metadata": {}, 121 | "outputs": [ 122 | { 123 | "data": { 124 | "text/plain": [ 125 | "0" 126 | ] 127 | }, 128 | "execution_count": 11, 129 | "metadata": {}, 130 | "output_type": "execute_result" 131 | } 132 | ], 133 | "source": [ 134 | "# Repositionnement du curseur comme pour un fichier\n", 135 | "f.seek(0)" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 12, 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "data": { 145 | "text/plain": [ 146 | "\"Voici une chaine de caractères toute simple. Deuxième ligne de cet objet qui a tout d'un fichier\"" 147 | ] 148 | }, 149 | "execution_count": 12, 150 | "metadata": {}, 151 | "output_type": "execute_result" 152 | } 153 | ], 154 | "source": [ 155 | "# Nouvelle lecture\n", 156 | "f.read()" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "Et voilà !\n", 164 | "Nous avons vu comment utiliser StringIO pour transformer une chaine de caractères en un objet fichier stocké en mémoire.\n", 165 | "Ceci a de nombreux cas d'utilisation, par exemple en Web Scraping pour lire le texte extrait des pages Web comme un fichier.\n" 166 | ] 167 | } 168 | ], 169 | "metadata": { 170 | "kernelspec": { 171 | "display_name": "Python 3", 172 | "language": "python", 173 | "name": "python3" 174 | }, 175 | "language_info": { 176 | "codemirror_mode": { 177 | "name": "ipython", 178 | "version": 3 179 | }, 180 | "file_extension": ".py", 181 | "mimetype": "text/x-python", 182 | "name": "python", 183 | "nbconvert_exporter": "python", 184 | "pygments_lexer": "ipython3", 185 | "version": "3.7.7" 186 | } 187 | }, 188 | "nbformat": 4, 189 | "nbformat_minor": 1 190 | } 191 | -------------------------------------------------------------------------------- /99-a positionner/07_MultiProcessing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [] 11 | } 12 | ], 13 | "metadata": { 14 | "kernelspec": { 15 | "display_name": "Python 2", 16 | "language": "python", 17 | "name": "python2" 18 | }, 19 | "language_info": { 20 | "codemirror_mode": { 21 | "name": "ipython", 22 | "version": 2 23 | }, 24 | "file_extension": ".py", 25 | "mimetype": "text/x-python", 26 | "name": "python", 27 | "nbconvert_exporter": "python", 28 | "pygments_lexer": "ipython2", 29 | "version": "2.7.10" 30 | } 31 | }, 32 | "nbformat": 4, 33 | "nbformat_minor": 0 34 | } 35 | -------------------------------------------------------------------------------- /FAQ.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Foire aux questions" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "1. Où puis-je trouver les blocs-notes Jupyter du cours?\n", 15 | "\n", 16 | "Vous pouvez les trouver ici." 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "2. Comment puis-je télécharger les blocs-notes?\n", 24 | "\n", 25 | "Cliquez sur le bouton de téléchargement en haut à droite de la page nbviewer. Sinon, pour télécharger tout à la fois, vous pouvez accéder à la page GitHub ici, puis cliquer sur le bouton de téléchargement pour télécharger tous les fichiers du portable (.ipynb) sur votre ordinateur (comprimé sous forme de fichier zip, vous devez le décompresser)." 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": { 31 | "collapsed": true 32 | }, 33 | "source": [ 34 | "3. Comment puis-je savoir où sont enregistrés mes blocs-notes ?\n", 35 | "\n", 36 | "Pour connaitre le dossier dans lequel un bloc-note est enregistré, il suffit de taper la commande : pwd dans une cellule. Cela va afficher votre répertoire de travail." 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "4. Comment puis-je modifier l'emplacement où les blocs-notes sont enregistrés?\n", 44 | "\n", 45 | "Vous devez pour cela changer le répertoire dans lequel vous démarrez Jupyter. Utilisez cd dans le terminal ou à l'invite de commandes pour passer au répertoire souhaité." 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "5. Comment puis-je ouvrir des fichiers .ipynb? Quel programme dois-je choisir?\n", 53 | "\n", 54 | "Les fichiers avec pour extension .jpynb sont des fichiers de bloc-notes Jupyter, pour pouvoir les ouvrir vous devez avoir installé Python et le système Jupyter. \n", 55 | "Consultez la leçon sur la préparation de votre environnement de travail pour plus de détails sur l'installation de Python et du système Jupyter. Une fois que vous avez Python et le système Jupyter installé vous êtes prêt à ouvrir les blocs-notes en procédant comme ci dessous :\n", 56 | "\n", 57 | " 1. Ouvrez d'abord votre Invite de commande (cmd sur une machine Windows, le terminal sur Mac ou Linux).\n", 58 | " 2. Ensuite dans votre terminal / invite de commande tapez pwd et appuyez sur Entrée (cela va afficher votre répertoire de travail)\n", 59 | " 3. Prenez note de ce répertoire, c'est à cet endroit que vous devez enregistrer vos fichiers .ipynb (ou le dossier contenant vos fichiers .ipynb)\n", 60 | " 4. Une fois que vos fichiers ipynb ou le dossier contenant ces fichiers est dans l'emplacement affiché à partir de l'étape pwd, retournez à votre terminal et tapez Jupyter notebook et appuyez sur Entrée.\n", 61 | " 5. Après l'étape 4, vous devriez avoir un onglet de votre navigateur ouvert avec la racine des fichiers du système Jupyter présenté à l'intérieur de celui-ci.\n", 62 | " 6. Cliquez sur votre bloc-notes (ou allez dans votre dossier de blocs-notes) affiché dans l’onglet du navigateur et celui-ci s'ouvrira dans un nouvel onglet avec ce bloc-notes que vous avez sélectionné.\n", 63 | " 7. Vous devriez maintenant pouvoir ouvrir les fichiers blocs-notes sans difficulté.\n" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "6. Comment afficher les conseils? Comment afficher les « DocStrings » pour les fonctions? etc...\n", 71 | "\n", 72 | "Vous pouvez utiliser Shift + Tab quand vous positionnez le curseur après un objet ou une fonction pour que iPython révèle la chaîne de caractères ou plus d'informations." 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "7. Comment utiliser l’auto-complétion ?\n", 80 | "\n", 81 | "Vous pouvez utiliser la touche de tabulation pour taper automatiquement le nom des méthodes, des objets ou des fonctions. Si plusieurs options sont disponibles, elles s’affichent et vous pourrez choisir celle que vous retenez." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": { 88 | "collapsed": true 89 | }, 90 | "outputs": [], 91 | "source": [] 92 | } 93 | ], 94 | "metadata": { 95 | "anaconda-cloud": {}, 96 | "kernelspec": { 97 | "display_name": "Python [default]", 98 | "language": "python", 99 | "name": "python3" 100 | }, 101 | "language_info": { 102 | "codemirror_mode": { 103 | "name": "ipython", 104 | "version": 3 105 | }, 106 | "file_extension": ".py", 107 | "mimetype": "text/x-python", 108 | "name": "python", 109 | "nbconvert_exporter": "python", 110 | "pygments_lexer": "ipython3", 111 | "version": "3.5.2" 112 | } 113 | }, 114 | "nbformat": 4, 115 | "nbformat_minor": 0 116 | } 117 | -------------------------------------------------------------------------------- /Jupyter (iPython) Notebooks Guide.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Guide to Using Jupyter Notebooks\n", 8 | "In this lecture we will be going over the basics of the Jupyter (previously called iPython Notebooks).\n", 9 | "\n", 10 | "For a complete User Manual check out the [Bryn Mawr College Computer Science Guide](http://jupyter.cs.brynmawr.edu/hub/dblank/public/Jupyter%20Notebook%20Users%20Manual.ipynb).\n", 11 | "\n", 12 | "Most of the breakdown will actually occur in the presentation corresponding to this Notebook. So please refer to either the presentation or the full User Manual linked above." 13 | ] 14 | } 15 | ], 16 | "metadata": { 17 | "kernelspec": { 18 | "display_name": "Python 2", 19 | "language": "python", 20 | "name": "python2" 21 | }, 22 | "language_info": { 23 | "codemirror_mode": { 24 | "name": "ipython", 25 | "version": 2 26 | }, 27 | "file_extension": ".py", 28 | "mimetype": "text/x-python", 29 | "name": "python", 30 | "nbconvert_exporter": "python", 31 | "pygments_lexer": "ipython2", 32 | "version": "2.7.11" 33 | } 34 | }, 35 | "nbformat": 4, 36 | "nbformat_minor": 0 37 | } 38 | -------------------------------------------------------------------------------- /Mon bloc note.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Mon premier bloc note\n", 8 | "voici du texte" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": { 15 | "collapsed": false 16 | }, 17 | "outputs": [ 18 | { 19 | "data": { 20 | "text/plain": [ 21 | "4" 22 | ] 23 | }, 24 | "execution_count": 1, 25 | "metadata": {}, 26 | "output_type": "execute_result" 27 | } 28 | ], 29 | "source": [ 30 | "2+2" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "metadata": { 37 | "collapsed": false 38 | }, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "Bonjour tout le monde !\n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "print(\"Bonjour tout le monde !\")" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": { 56 | "collapsed": true 57 | }, 58 | "outputs": [], 59 | "source": [] 60 | } 61 | ], 62 | "metadata": { 63 | "anaconda-cloud": {}, 64 | "kernelspec": { 65 | "display_name": "Python [default]", 66 | "language": "python", 67 | "name": "python3" 68 | }, 69 | "language_info": { 70 | "codemirror_mode": { 71 | "name": "ipython", 72 | "version": 3 73 | }, 74 | "file_extension": ".py", 75 | "mimetype": "text/x-python", 76 | "name": "python", 77 | "nbconvert_exporter": "python", 78 | "pygments_lexer": "ipython3", 79 | "version": "3.5.2" 80 | } 81 | }, 82 | "nbformat": 4, 83 | "nbformat_minor": 1 84 | } 85 | -------------------------------------------------------------------------------- /Mon premier bloc note.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Le titre\n", 8 | "le détail" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 3, 14 | "metadata": { 15 | "collapsed": false 16 | }, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "Bonjour tout le monde !\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "print(\"Bonjour tout le monde !\")" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": { 34 | "collapsed": true 35 | }, 36 | "outputs": [], 37 | "source": [] 38 | } 39 | ], 40 | "metadata": { 41 | "anaconda-cloud": {}, 42 | "kernelspec": { 43 | "display_name": "Python [default]", 44 | "language": "python", 45 | "name": "python3" 46 | }, 47 | "language_info": { 48 | "codemirror_mode": { 49 | "name": "ipython", 50 | "version": 3 51 | }, 52 | "file_extension": ".py", 53 | "mimetype": "text/x-python", 54 | "name": "python", 55 | "nbconvert_exporter": "python", 56 | "pygments_lexer": "ipython3", 57 | "version": "3.5.2" 58 | } 59 | }, 60 | "nbformat": 4, 61 | "nbformat_minor": 1 62 | } 63 | -------------------------------------------------------------------------------- /Pierian_Data_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/Pierian_Data_Logo.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python 3 : Formation complète à la programmation 2 | 3 | Python 3 : Formation complète à la programmation 4 | 5 | Vous allez trouver ici tous les documents (Jupyter Notebooks) qui accompagnent le cours [Python 3 : Formation complète à la programmation](https://www.udemy.com/course/python-formation-intensive-a-la-programmation/?referralCode=B0B80849C6B1A202A0FF). 6 | 7 | N'hésitez pas à me contacter si vous désirez en savoir plus ou bénéficier d'une promotion. 8 | 9 | ## Programme 10 | 11 | * Python_Notions_de_Base 12 | * Python_Déclarations 13 | * Méthodes_et_Fonctions 14 | 15 | * Premier_Projet 16 | 17 | * Programmation_Orientée_Objet 18 | * Erreurs_et_Exceptions 19 | 20 | * Deuxième_Projet 21 | 22 | * Modules_et_Paquets 23 | * Fonctions_Intégrées 24 | * Décorateurs 25 | * Itérateurs et Générateurs 26 | 27 | * Projet_Final 28 | 29 | * Modules_Python_Avancés 30 | 31 | 32 | ## Remarque 33 | Ces documents accompagnent le cours [Python 3 : Formation complète à la programmation](https://www.udemy.com/course/python-formation-intensive-a-la-programmation/?referralCode=B0B80849C6B1A202A0FF) disponible en ligne sur Udemy. 34 | 35 | Il s'agit de la version Française du cours [Complete Python Bootcamp](https://www.udemy.com/complete-python-bootcamp/?couponCode=COMPLETE_GITHUB) vendu à plus d'un million d'exemplaires, traduite et adaptée par [Marc Augier](https://www.udemy.com/user/marcaugier/) avec le soutien de l'auteur orginal [José Portilla](https://www.udemy.com/user/joseportilla/). 36 | 37 | N'hésitez pas à me contacter si vous désirez en savoir plus ou bénéficier d'une promotion. 38 | 39 | ## vous avez aimé ? 40 | Pourquoi pas me remercier en m'offrant un café ? 41 | 42 | Buy Me A Coffee 43 | 44 | Réalisé par [@marcyves](https://github.com/marcyves) 45 | 46 | ## Notice 47 | 48 |

Licence

49 | 50 | Ces scripts sont mis à disposition selon les termes de la [Licence Creative Commons Attribution - Partage dans les Mêmes Conditions 3.0 France](https://creativecommons.org/licenses/by-sa/3.0/fr/). 51 | 52 | -------------------------------------------------------------------------------- /logo_XDM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcyves/Python-3-Formation-complete/2832c00fbe465e2c6156ddb63d26ebba865c91d6/logo_XDM.png --------------------------------------------------------------------------------