diff --git a/2_base_programmation.ipynb b/2_base_programmation.ipynb index 13a2e5f..afab488 100644 --- a/2_base_programmation.ipynb +++ b/2_base_programmation.ipynb @@ -189,8 +189,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-15T13:12:05.927679Z", - "start_time": "2024-10-15T13:12:05.885039Z" + "end_time": "2024-10-25T15:36:39.333391Z", + "start_time": "2024-10-25T15:36:39.290265Z" } }, "cell_type": "code", @@ -246,8 +246,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-15T13:12:05.940537Z", - "start_time": "2024-10-15T13:12:05.934294Z" + "end_time": "2024-10-25T15:36:39.345249Z", + "start_time": "2024-10-25T15:36:39.339260Z" } }, "cell_type": "code", @@ -282,8 +282,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-15T13:12:05.962319Z", - "start_time": "2024-10-15T13:12:05.956248Z" + "end_time": "2024-10-25T15:36:39.363125Z", + "start_time": "2024-10-25T15:36:39.356733Z" } }, "cell_type": "code", @@ -329,7 +329,8 @@ "cell_type": "markdown", "source": [ "Écrire un script Python appelé `leap_year.py` qui vérifie si une année saisie par l'utilisateur est une année bissextile ou non.\n", - "Sachant qu'une année est bissextile si elle est divisible par 4 ou 100 ou 400.\n", + "Sachant qu'une année est bissextile si elle est divisible par 4 mais pas par 100 à l'exception\n", + " de celles divisible par 400 (voir https://fr.wikipedia.org/wiki/Ann%C3%A9e_bissextile).\n", "- Attention aux commentaires\n", "- Attention aux noms de variables. \n", "*Faites valider votre script ainsi que son exécution*. " diff --git a/3_boucles_iteratives.ipynb b/3_boucles_iteratives.ipynb index 3e8dc93..875609a 100644 --- a/3_boucles_iteratives.ipynb +++ b/3_boucles_iteratives.ipynb @@ -38,8 +38,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-15T13:25:18.677732Z", - "start_time": "2024-10-15T13:25:18.325994Z" + "end_time": "2024-10-25T15:36:33.991978Z", + "start_time": "2024-10-25T15:36:33.698158Z" } }, "cell_type": "code", @@ -76,11 +76,7 @@ }, { "metadata": { - "trusted": false, - "ExecuteTime": { - "end_time": "2024-10-15T13:25:18.682650Z", - "start_time": "2024-10-15T13:25:18.682322Z" - } + "trusted": false }, "cell_type": "code", "source": [ @@ -202,11 +198,7 @@ }, { "metadata": { - "trusted": false, - "ExecuteTime": { - "end_time": "2024-10-15T13:25:18.687959Z", - "start_time": "2024-10-15T13:25:18.687654Z" - } + "trusted": false }, "cell_type": "code", "source": "#Syntaxe d'écriture\nfor variable in collection:\n instruction1", @@ -356,6 +348,10 @@ "\n", "current_year = datetime.datetime.now().year\n", "for year in range(current_year, current_year + 100):\n", + " \"\"\"\n", + " According to https://fr.wikipedia.org/wiki/Ann%C3%A9e_bissextile\n", + " Les années sont bissextiles si elles sont multiples de quatre, mais pas si elles sont multiples de cent, à l'exception des années multiples de quatre cents qui, elles, sont également bissextiles. Ainsi, les années 2020, 2024 et 2028 sont bissextiles, de même que 2000 ou 2400, mais pas 1900, 2100, 2200 et 2300. \n", + " \"\"\"\n", " if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:\n", " break\n", "print(\"La dernière année bissextile est: \", year)" @@ -521,10 +517,10 @@ "# Exemple de l'utilisation de map\n", "# On met au carré chaque élément de la liste\n", "numbers = [1, 2, 3, 4]\n", - "squared_numbers = list(map(lambda x: x**2, numbers))\n", + "squared_numbers = list(map(lambda x: x ** 2, numbers))\n", "print(squared_numbers)\n", "# On a besoin de list() map est un objet qui n'affiche pas les valeurs\n", - "map_squared_numbers = map(lambda x: x**2, numbers)\n", + "map_squared_numbers = map(lambda x: x ** 2, numbers)\n", "print(\"Object \", map_squared_numbers, \"is of type: \", type(map_squared_numbers))\n", "# Mais il est itérable\n", "for number in map_squared_numbers:\n", @@ -548,14 +544,23 @@ "# Exemple de l'utilisation de map\n", "# On met au carré chaque élément de la liste\n", "numbers = [1, 2, 3, 4]\n", - "squared_numbers = [x**2 for x in numbers]\n", + "squared_numbers = [x ** 2 for x in numbers]\n", "print(squared_numbers)\n", "# On peut filtrer les éléments\n", "even_numbers = [x for x in numbers if x % 2 == 0]\n", "print(even_numbers)" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16]\n", + "[2, 4]\n" + ] + } + ], + "execution_count": 2 }, { "metadata": {}, @@ -564,6 +569,58 @@ "Les performances peuvent être meilleures avec `map` mais dans certains cas seulement, il faut voir au cas par cas.\n", "Voir le ticket StackOverflow https://stackoverflow.com/questions/1247486/list-comprehension-vs-map." ] + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "***\n", + "## Unpack avec l'operateur splat `*`\n", + "\n", + "### Unpack d'iterables\n", + "\n", + "On peut créer un nouveau itérable avec `*` et une autre valeur :" + ] + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-29T22:26:57.520669Z", + "start_time": "2024-10-29T22:26:57.518362Z" + } + }, + "cell_type": "code", + "source": [ + "assert [1, *[2, 3, 4]] == [1, 2, 3, 4] # Un itérable et une valeur\n", + "assert [*[1, 2], *[3, 4]] == [1, 2, 3, 4] # 2 Itérables\n", + "assert [*[1, 2], *(3, 4)] == [1, 2, 3, 4] # 2 Itérables, tuple ou liste" + ], + "outputs": [], + "execution_count": 3 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "### Unpack de dictionnaires avec `**`\n", + "\n", + "Il est également possible de manipuler les dictionnaires pour en créer de nouveau avec `*` :" + ] + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-29T22:29:57.962047Z", + "start_time": "2024-10-29T22:29:57.959603Z" + } + }, + "cell_type": "code", + "source": [ + "assert {1: 1, **{2: 2, 3: 3}} == {1: 1, 2: 2, 3: 3}\n", + "assert {**{1: 1, 2: 2}, **{3: 3}} == {1: 1, 2: 2, 3: 3}" + ], + "outputs": [], + "execution_count": 5 } ], "metadata": { diff --git a/5_fonctions.ipynb b/5_fonctions.ipynb index 793973f..317ded9 100644 --- a/5_fonctions.ipynb +++ b/5_fonctions.ipynb @@ -3,9 +3,7 @@ { "cell_type": "markdown", "metadata": {}, - "source": [ - "# Programmation Python 3 - Les fonctions" - ] + "source": "# Programmation Python 3 - Les fonctions" }, { "cell_type": "markdown", @@ -92,8 +90,8 @@ "cell_type": "code", "metadata": { "ExecuteTime": { - "end_time": "2024-10-15T13:50:38.869965Z", - "start_time": "2024-10-15T13:50:38.863648Z" + "end_time": "2024-10-25T15:36:52.516009Z", + "start_time": "2024-10-25T15:36:52.506378Z" } }, "source": [ @@ -150,7 +148,12 @@ }, { "cell_type": "code", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:52.529363Z", + "start_time": "2024-10-25T15:36:52.521126Z" + } + }, "source": [ "#Exemple de déclaration d'une fonction sans argument\n", "#----- Début Declaration de fonctions -----\n", @@ -164,8 +167,16 @@ "message_de_bienvenue()\n", "#----- Fin Programme Principal -----" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bienvenue dans le chapitre sur les fonctions\n" + ] + } + ], + "execution_count": 2 }, { "cell_type": "markdown", @@ -180,7 +191,12 @@ }, { "cell_type": "code", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:52.543230Z", + "start_time": "2024-10-25T15:36:52.533215Z" + } + }, "source": [ "#Exemple de déclaration d'une fonction avec arguments\n", "#----- Début Declaration de fonctions -----\n", @@ -197,8 +213,18 @@ "message_de_bienvenue(mon_message, nb_repetitions)\n", "#----- Fin Programme Principal -----" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bonjour\n", + "Bonjour\n", + "Bonjour\n" + ] + } + ], + "execution_count": 3 }, { "cell_type": "markdown", @@ -211,7 +237,12 @@ }, { "cell_type": "code", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:52.599046Z", + "start_time": "2024-10-25T15:36:52.591300Z" + } + }, "source": [ "# Exemple de déclaration d'une fonction retournant une valeur\n", "# ----- Début Declaration de fonctions -----\n", @@ -231,8 +262,17 @@ "print(ex2_somme)\n", "# ----- Fin Programme Principal -----" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "124.53\n", + "67.19\n" + ] + } + ], + "execution_count": 4 }, { "cell_type": "markdown", @@ -250,7 +290,12 @@ }, { "cell_type": "code", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:52.626492Z", + "start_time": "2024-10-25T15:36:52.619617Z" + } + }, "source": [ "# Exemple de déclaration d'une fonction avec annotations\n", "# ----- Début Declaration de fonctions -----\n", @@ -270,8 +315,17 @@ "print(ex2_somme)\n", "# ----- Fin Programme Principal -----" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "124.53\n", + "67.19\n" + ] + } + ], + "execution_count": 5 }, { "cell_type": "markdown", @@ -314,7 +368,12 @@ }, { "cell_type": "code", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:52.821268Z", + "start_time": "2024-10-25T15:36:52.813006Z" + } + }, "source": [ "# Exemple de déclaration d'une variable globale\n", "# ----- Début déclaration variable globale -----\n", @@ -341,8 +400,18 @@ "print(\"Affichage valeur de la variable globale res: \", res)\n", "# ----- Fin Programme Principal -----" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "124.53\n", + "67.19\n", + "Affichage valeur de la variable globale res: 0\n" + ] + } + ], + "execution_count": 6 }, { "cell_type": "markdown", @@ -355,7 +424,12 @@ }, { "cell_type": "code", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:52.844616Z", + "start_time": "2024-10-25T15:36:52.834592Z" + } + }, "source": [ "# Exemple de déclaration d'une variable globale\n", "# ----- Début déclaration variable globale -----\n", @@ -383,8 +457,18 @@ "print(\"Affichage valeur de la variable globale res: \", res)\n", "# ----- Fin Programme Principal -----" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "124.53\n", + "67.19\n", + "Affichage valeur de la variable globale res: 67.19\n" + ] + } + ], + "execution_count": 7 }, { "cell_type": "markdown", @@ -418,7 +502,12 @@ }, { "cell_type": "code", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:52.943393Z", + "start_time": "2024-10-25T15:36:52.933491Z" + } + }, "source": [ "# Exemple de déclaration d'une variable globale\n", "# ----- Début déclaration variable globale -----\n", @@ -452,8 +541,18 @@ "print(\"Affichage valeur de la variable globale res: \", res)\n", "# ----- Fin Programme Principal -----" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "124.53\n", + "0\n", + "Affichage valeur de la variable globale res: 0\n" + ] + } + ], + "execution_count": 8 }, { "cell_type": "markdown", @@ -524,7 +623,12 @@ ] }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:52.975402Z", + "start_time": "2024-10-25T15:36:52.968145Z" + } + }, "cell_type": "code", "source": [ "is_even = lambda n: n % 2 == 0\n", @@ -532,8 +636,17 @@ "is_odd = lambda n: not is_even(n)\n", "print(\"Is 5 odd: \", is_odd(5))" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Is 5 even: False\n", + "Is 5 odd: True\n" + ] + } + ], + "execution_count": 9 }, { "metadata": {}, @@ -541,7 +654,12 @@ "source": "Toujours inspirée de la programmation fonctionnelle, cette syntaxe est souvent utilisée avec `map`, `functools.reduce`, `functools.filter`." }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:53.063846Z", + "start_time": "2024-10-25T15:36:53.055237Z" + } + }, "cell_type": "code", "source": [ "# Liste les booléens jusqu'à 10\n", @@ -551,8 +669,17 @@ "# functools (https://docs.python.org/fr/3/library/functools.html) à programmation fonctionnelle.\n", "print(list(filter(is_odd, range(10))))" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, True, False, True, False, True, False, True, False, True]\n", + "[1, 3, 5, 7, 9]\n" + ] + } + ], + "execution_count": 10 }, { "metadata": {}, @@ -576,7 +703,12 @@ ] }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:53.081768Z", + "start_time": "2024-10-25T15:36:53.074485Z" + } + }, "cell_type": "code", "source": [ "from functools import partial\n", @@ -584,8 +716,16 @@ "int_bin = partial(int, base=2)\n", "print(\"En base 10, 0101110 vaut: \", int_bin(\"0101110\"))" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "En base 10, 0101110 vaut: 46\n" + ] + } + ], + "execution_count": 11 }, { "metadata": {}, @@ -632,7 +772,12 @@ ] }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:53.148434Z", + "start_time": "2024-10-25T15:36:53.140383Z" + } + }, "cell_type": "code", "source": [ "# Décorateur sans argument inspiré de https://python.doctor/page-decorateurs-decorator-python-cours-debutants\n", @@ -657,8 +802,16 @@ "\n", "do_that()" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Execution des instructions\n" + ] + } + ], + "execution_count": 12 }, { "metadata": {}, @@ -670,7 +823,12 @@ ] }, { - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-25T15:36:53.227234Z", + "start_time": "2024-10-25T15:36:53.195913Z" + } + }, "cell_type": "code", "source": [ "import time\n", @@ -733,8 +891,337 @@ "\n", "is_prime(23438545412552424235452557522453354357674555425)" ], - "outputs": [], - "execution_count": null + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0002 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0002 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0003 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(5,) {} Took 0.0004 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(6,) {} Took 0.0006 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(5,) {} Took 0.0004 seconds\n", + "Function fibonacci(7,) {} Took 0.0011 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0001 seconds\n", + "Function fibonacci(4,) {} Took 0.0003 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(5,) {} Took 0.0004 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(6,) {} Took 0.0007 seconds\n", + "Function fibonacci(8,) {} Took 0.0018 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(5,) {} Took 0.0003 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(6,) {} Took 0.0005 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(5,) {} Took 0.0003 seconds\n", + "Function fibonacci(7,) {} Took 0.0009 seconds\n", + "Function fibonacci(9,) {} Took 0.0027 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(5,) {} Took 0.0003 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(6,) {} Took 0.0005 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(5,) {} Took 0.0003 seconds\n", + "Function fibonacci(7,) {} Took 0.0009 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0003 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0003 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0001 seconds\n", + "Function fibonacci(4,) {} Took 0.0004 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(5,) {} Took 0.0005 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(3,) {} Took 0.0001 seconds\n", + "Function fibonacci(1,) {} Took 0.0000 seconds\n", + "Function fibonacci(0,) {} Took 0.0000 seconds\n", + "Function fibonacci(2,) {} Took 0.0000 seconds\n", + "Function fibonacci(4,) {} Took 0.0002 seconds\n", + "Function fibonacci(6,) {} Took 0.0007 seconds\n", + "Function fibonacci(8,) {} Took 0.0016 seconds\n", + "Function fibonacci(10,) {} Took 0.0044 seconds\n", + "Function is_prime(23438545412552424235452557522453354357674555425,) {} Took 0.0000 seconds\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 13 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "***\n", + "### Passage d'arguments avec splat `*`\n", + "\n", + "### Passage d'un nombre indéterminé d'arguments\n", + "\n", + "Après, les arguments positionnels et les kwargs, on peut passer un nombre infini d'arguments qui se retrouveront sous forme de liste\n", + "dans la variable préfixée par `*`. Par convention cette dernière est le plus souvent appelé args." + ] + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-29T22:08:30.250541Z", + "start_time": "2024-10-29T22:08:30.248078Z" + } + }, + "cell_type": "code", + "source": [ + "def multiply(*args):\n", + " res = 1\n", + " for i in args:\n", + " res = res * i\n", + " return res\n", + "\n", + "\n", + "print(\"10 * 10 * 10 font:\", multiply(10, 10, 10))" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 * 10 * 10 font: 1000\n" + ] + } + ], + "execution_count": 7 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "### Passage d'un nombre indéterminé de *keyword arguments*\n", + "\n", + "Les *keyword arguments* placés à la fin, après les arguments positionnels, les *keyword arguments*, les `*args` vus plus haut, se retrouvent sous forme de dictionnaire dans une variable préfixée par `**`. Par convention cette dernière est le plus souvent appelé `kwargs`." + ] + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-29T22:15:48.732786Z", + "start_time": "2024-10-29T22:15:48.730139Z" + } + }, + "cell_type": "code", + "source": [ + "def afficher_recette(recette, **ingredients): # ingrédients sera un dictionnaire\n", + " print(recette)\n", + " for ingredient in ingredients.items():\n", + " print(\" - %s: %s\" % ingredient)\n", + "\n", + "\n", + "afficher_recette(\n", + " \"Jambon beurre\",\n", + " Pain=\"frais\", # on doit donner le nom de ce paramètre\n", + " Jambon=\"cuit\",\n", + " beurre=\"pas trop\"\n", + ")" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Jambon beurre\n", + " - Pain: frais\n", + " - Jambon: cuit\n", + " - beurure: pas trop\n" + ] + } + ], + "execution_count": 8 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "***\n", + "### Fonction avec tous les types d'arguments\n", + "\n", + "Les différents arguments doivent être dans le bon ordre :" + ] + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-10-29T22:18:16.168765Z", + "start_time": "2024-10-29T22:18:16.165924Z" + } + }, + "cell_type": "code", + "source": [ + "def affichage_hybride(\n", + " parametre_normal,\n", + " parametre_avec_default=\"valeur par défaut\",\n", + " *args,\n", + " **kwargs\n", + "):\n", + " print(parametre_normal)\n", + " print(parametre_avec_default)\n", + " print(args)\n", + " print(kwargs)\n", + "\n", + "\n", + "affichage_hybride(\"param1\", \"param2\", \"infini1\", \"infini2\", kwinfini1=1, kwinfini2=2)" + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "param1\n", + "param2\n", + "('infini1', 'infini2')\n", + "{'kwinfini1': 1, 'kwinfini2': 2}\n" + ] + } + ], + "execution_count": 9 } ], "metadata": { diff --git a/6_types_iterables.ipynb b/6_types_iterables.ipynb index e5f06b0..0f2f0ac 100644 --- a/6_types_iterables.ipynb +++ b/6_types_iterables.ipynb @@ -78,8 +78,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:50.435390Z", - "start_time": "2024-10-08T21:00:50.428188Z" + "end_time": "2024-10-25T15:37:05.311217Z", + "start_time": "2024-10-25T15:37:05.303714Z" } }, "cell_type": "code", @@ -102,7 +102,7 @@ ] } ], - "execution_count": 10 + "execution_count": 2 }, { "metadata": {}, @@ -117,8 +117,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:51.060128Z", - "start_time": "2024-10-08T21:00:51.052554Z" + "end_time": "2024-10-25T15:37:05.865376Z", + "start_time": "2024-10-25T15:37:05.858162Z" } }, "cell_type": "code", @@ -141,7 +141,7 @@ ] } ], - "execution_count": 11 + "execution_count": 3 }, { "metadata": {}, @@ -152,8 +152,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:51.144589Z", - "start_time": "2024-10-08T21:00:51.106302Z" + "end_time": "2024-10-25T15:37:06.219838Z", + "start_time": "2024-10-25T15:37:05.907812Z" } }, "cell_type": "code", @@ -170,12 +170,12 @@ "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)", - "Cell \u001B[0;32mIn[12], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;66;03m# Exemple d'opération interdite\u001B[39;00m\n\u001B[1;32m 2\u001B[0m who \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mDigicomp Academy\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m----> 3\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[43mwho\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43m \u001B[49m\u001B[43mwho\u001B[49m)\n", + "Cell \u001B[0;32mIn[4], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;66;03m# Exemple d'opération interdite\u001B[39;00m\n\u001B[1;32m 2\u001B[0m who \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mDigicomp Academy\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m----> 3\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[43mwho\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43m \u001B[49m\u001B[43mwho\u001B[49m)\n", "\u001B[0;31mTypeError\u001B[0m: can't multiply sequence by non-int of type 'str'" ] } ], - "execution_count": 12 + "execution_count": 4 }, { "metadata": {}, @@ -192,11 +192,7 @@ }, { "metadata": { - "trusted": false, - "ExecuteTime": { - "end_time": "2024-10-08T21:00:51.359101Z", - "start_time": "2024-10-08T21:00:51.352336Z" - } + "trusted": false }, "cell_type": "code", "source": [ @@ -207,18 +203,8 @@ "print(ma_liste)\n", "print(liste_formes + ma_liste)" ], - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['Triangle', 'Cercle', 'Quadrilatère']\n", - "['Bonjour', False, 0, 1, 3.14159]\n", - "['Triangle', 'Cercle', 'Quadrilatère', 'Bonjour', False, 0, 1, 3.14159]\n" - ] - } - ], - "execution_count": 13 + "outputs": [], + "execution_count": null }, { "metadata": {}, @@ -231,11 +217,7 @@ }, { "metadata": { - "trusted": false, - "ExecuteTime": { - "end_time": "2024-10-08T21:00:51.815162Z", - "start_time": "2024-10-08T21:00:51.807883Z" - } + "trusted": false }, "cell_type": "code", "source": [ @@ -247,19 +229,8 @@ "print(couleurs[-1])\n", "print(couleurs[-3])" ], - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Rouge\n", - "Bleu\n", - "Jaune\n", - "Bleu\n" - ] - } - ], - "execution_count": 14 + "outputs": [], + "execution_count": null }, { "metadata": {}, @@ -273,11 +244,7 @@ }, { "metadata": { - "trusted": false, - "ExecuteTime": { - "end_time": "2024-10-08T21:00:51.962818Z", - "start_time": "2024-10-08T21:00:51.955514Z" - } + "trusted": false }, "cell_type": "code", "source": [ @@ -291,19 +258,8 @@ "liste_pair = list(range(0, 10, 2))\n", "print(liste_pair)" ], - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n", - "[5, 6, 7, 8, 9]\n", - "[1, 3, 5, 7, 9]\n", - "[0, 2, 4, 6, 8]\n" - ] - } - ], - "execution_count": 15 + "outputs": [], + "execution_count": null }, { "metadata": {}, @@ -352,8 +308,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:52.117395Z", - "start_time": "2024-10-08T21:00:52.111199Z" + "end_time": "2024-10-25T15:37:06.257442Z", + "start_time": "2024-10-25T15:37:06.251630Z" } }, "cell_type": "code", @@ -378,7 +334,7 @@ ] } ], - "execution_count": 16 + "execution_count": 5 }, { "metadata": {}, @@ -389,8 +345,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:52.170115Z", - "start_time": "2024-10-08T21:00:52.163948Z" + "end_time": "2024-10-25T15:37:06.372664Z", + "start_time": "2024-10-25T15:37:06.366098Z" } }, "cell_type": "code", @@ -414,24 +370,27 @@ ] } ], - "execution_count": 17 + "execution_count": 6 }, { "metadata": {}, "cell_type": "markdown", - "source": "On constate donc que les deux listes ont été modifiées. " + "source": [ + "On constate donc que les deux listes ont été modifiées suite à l'égalité.\n", + "Concernant la copie, la méthode `copy()` est peut-être plus lisible, la méthode `[:]` ressemble trop au slicing." + ] }, { "metadata": {}, "cell_type": "markdown", - "source": "Il est possible faire une copie qui est indépendante de la première par l'intermédiaire du caractère *:*" + "source": "Il est possible faire une copie qui est indépendante de la première par l'intermédiaire du caractère `:` ou de la méthode `copy()` : " }, { "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:52.303520Z", - "start_time": "2024-10-08T21:00:52.297524Z" + "end_time": "2024-10-25T15:37:06.961186Z", + "start_time": "2024-10-25T15:37:06.955243Z" } }, "cell_type": "code", @@ -439,6 +398,8 @@ "# Exemple d'une copie de liste indépendante\n", "couleurs = [\"Noir\", \"Marron\", \"Rouge\", \"Orange\"]\n", "colors = couleurs[:]\n", + "colors_another_copy = couleurs.copy()\n", + "print(\"Les copies sont identiques: \", colors == colors_another_copy)\n", "print(\"Liste copie: \", colors)\n", "colors[0] = \"Blanc\"\n", "print(\"Liste copie modifiée: \", colors)\n", @@ -449,13 +410,14 @@ "name": "stdout", "output_type": "stream", "text": [ + "Les copies sont identiques: True\n", "Liste copie: ['Noir', 'Marron', 'Rouge', 'Orange']\n", "Liste copie modifiée: ['Blanc', 'Marron', 'Rouge', 'Orange']\n", "Liste souche: ['Noir', 'Marron', 'Rouge', 'Orange']\n" ] } ], - "execution_count": 18 + "execution_count": 7 }, { "metadata": {}, @@ -506,8 +468,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:55.419579Z", - "start_time": "2024-10-08T21:00:52.451194Z" + "end_time": "2024-10-25T15:37:13.401634Z", + "start_time": "2024-10-25T15:37:07.012803Z" } }, "cell_type": "code", @@ -518,7 +480,7 @@ "mot = getpass(\"Veuillez saisir le mot secret: \")" ], "outputs": [], - "execution_count": 19 + "execution_count": 8 }, { "metadata": {}, @@ -576,8 +538,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:55.430952Z", - "start_time": "2024-10-08T21:00:55.423262Z" + "end_time": "2024-10-25T15:37:13.409711Z", + "start_time": "2024-10-25T15:37:13.404363Z" } }, "cell_type": "code", @@ -598,7 +560,7 @@ ] } ], - "execution_count": 20 + "execution_count": 9 }, { "metadata": {}, @@ -609,8 +571,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:55.442654Z", - "start_time": "2024-10-08T21:00:55.434036Z" + "end_time": "2024-10-25T15:37:13.520897Z", + "start_time": "2024-10-25T15:37:13.512723Z" } }, "cell_type": "code", @@ -634,7 +596,7 @@ ] } ], - "execution_count": 21 + "execution_count": 10 }, { "metadata": {}, @@ -648,8 +610,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:55.489141Z", - "start_time": "2024-10-08T21:00:55.463500Z" + "end_time": "2024-10-25T15:37:13.685439Z", + "start_time": "2024-10-25T15:37:13.647412Z" } }, "cell_type": "code", @@ -667,12 +629,12 @@ "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)", - "Cell \u001B[0;32mIn[22], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;66;03m# Exemple modification d'un tuple\u001B[39;00m\n\u001B[1;32m 2\u001B[0m couleurs_tuple \u001B[38;5;241m=\u001B[39m (\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mNoir\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mMarron\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mRouge\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mOrange\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m----> 3\u001B[0m \u001B[43mcouleurs_tuple\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m]\u001B[49m \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mBlanc\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 4\u001B[0m \u001B[38;5;28mprint\u001B[39m(couleurs_tuple)\n", + "Cell \u001B[0;32mIn[11], line 3\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[38;5;66;03m# Exemple modification d'un tuple\u001B[39;00m\n\u001B[1;32m 2\u001B[0m couleurs_tuple \u001B[38;5;241m=\u001B[39m (\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mNoir\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mMarron\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mRouge\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mOrange\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m----> 3\u001B[0m \u001B[43mcouleurs_tuple\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m]\u001B[49m \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mBlanc\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 4\u001B[0m \u001B[38;5;28mprint\u001B[39m(couleurs_tuple)\n", "\u001B[0;31mTypeError\u001B[0m: 'tuple' object does not support item assignment" ] } ], - "execution_count": 22 + "execution_count": 11 }, { "metadata": {}, @@ -688,8 +650,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:55.552062Z", - "start_time": "2024-10-08T21:00:55.546101Z" + "end_time": "2024-10-25T15:37:13.857188Z", + "start_time": "2024-10-25T15:37:13.851403Z" } }, "cell_type": "code", @@ -711,7 +673,7 @@ ] } ], - "execution_count": 23 + "execution_count": 12 }, { "metadata": {}, @@ -721,8 +683,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2024-10-08T21:00:55.630095Z", - "start_time": "2024-10-08T21:00:55.608194Z" + "end_time": "2024-10-25T15:37:14.000233Z", + "start_time": "2024-10-25T15:37:13.928823Z" } }, "cell_type": "code", @@ -738,12 +700,12 @@ "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)", - "Cell \u001B[0;32mIn[24], line 2\u001B[0m\n\u001B[1;32m 1\u001B[0m inchageable \u001B[38;5;241m=\u001B[39m (\u001B[38;5;241m1\u001B[39m, \u001B[38;5;241m2\u001B[39m, \u001B[38;5;241m3\u001B[39m)\n\u001B[0;32m----> 2\u001B[0m \u001B[43minchageable\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m]\u001B[49m \u001B[38;5;241m=\u001B[39m \u001B[38;5;241m4\u001B[39m\n", + "Cell \u001B[0;32mIn[13], line 2\u001B[0m\n\u001B[1;32m 1\u001B[0m inchangeable \u001B[38;5;241m=\u001B[39m (\u001B[38;5;241m1\u001B[39m, \u001B[38;5;241m2\u001B[39m, \u001B[38;5;241m3\u001B[39m)\n\u001B[0;32m----> 2\u001B[0m \u001B[43minchangeable\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m]\u001B[49m \u001B[38;5;241m=\u001B[39m \u001B[38;5;241m4\u001B[39m\n", "\u001B[0;31mTypeError\u001B[0m: 'tuple' object does not support item assignment" ] } ], - "execution_count": 24 + "execution_count": 13 }, { "metadata": {}, @@ -764,8 +726,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:55.770729Z", - "start_time": "2024-10-08T21:00:55.764559Z" + "end_time": "2024-10-25T15:37:14.455688Z", + "start_time": "2024-10-25T15:37:14.442342Z" } }, "cell_type": "code", @@ -787,7 +749,7 @@ ] } ], - "execution_count": 25 + "execution_count": 14 }, { "metadata": {}, @@ -806,8 +768,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:55.944961Z", - "start_time": "2024-10-08T21:00:55.939213Z" + "end_time": "2024-10-25T15:37:14.624621Z", + "start_time": "2024-10-25T15:37:14.619166Z" } }, "cell_type": "code", @@ -829,7 +791,7 @@ ] } ], - "execution_count": 26 + "execution_count": 15 }, { "metadata": {}, @@ -843,8 +805,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:56.032103Z", - "start_time": "2024-10-08T21:00:56.026101Z" + "end_time": "2024-10-25T15:37:14.707025Z", + "start_time": "2024-10-25T15:37:14.699828Z" } }, "cell_type": "code", @@ -861,12 +823,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "137178168204352 137178168204352\n", - "137178168204352 137178168204352\n" + "125278896047104 125278896047104\n", + "125278896047104 125278896047104\n" ] } ], - "execution_count": 27 + "execution_count": 16 }, { "metadata": {}, @@ -900,8 +862,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:56.156394Z", - "start_time": "2024-10-08T21:00:56.149810Z" + "end_time": "2024-10-25T15:37:14.819300Z", + "start_time": "2024-10-25T15:37:14.813964Z" } }, "cell_type": "code", @@ -926,7 +888,7 @@ ] } ], - "execution_count": 28 + "execution_count": 17 }, { "metadata": {}, @@ -945,8 +907,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:56.279070Z", - "start_time": "2024-10-08T21:00:56.272456Z" + "end_time": "2024-10-25T15:37:14.889885Z", + "start_time": "2024-10-25T15:37:14.883656Z" } }, "cell_type": "code", @@ -969,7 +931,7 @@ ] } ], - "execution_count": 29 + "execution_count": 18 }, { "metadata": {}, @@ -986,8 +948,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:56.425076Z", - "start_time": "2024-10-08T21:00:56.418297Z" + "end_time": "2024-10-25T15:37:15.060387Z", + "start_time": "2024-10-25T15:37:15.053800Z" } }, "cell_type": "code", @@ -1009,7 +971,7 @@ ] } ], - "execution_count": 30 + "execution_count": 19 }, { "metadata": {}, @@ -1020,8 +982,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:56.569721Z", - "start_time": "2024-10-08T21:00:56.562217Z" + "end_time": "2024-10-25T15:37:15.116396Z", + "start_time": "2024-10-25T15:37:15.111005Z" } }, "cell_type": "code", @@ -1042,7 +1004,7 @@ ] } ], - "execution_count": 31 + "execution_count": 20 }, { "metadata": {}, @@ -1062,8 +1024,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:56.639525Z", - "start_time": "2024-10-08T21:00:56.630154Z" + "end_time": "2024-10-25T15:37:15.276441Z", + "start_time": "2024-10-25T15:37:15.269467Z" } }, "cell_type": "code", @@ -1094,7 +1056,7 @@ ] } ], - "execution_count": 32 + "execution_count": 21 }, { "metadata": {}, @@ -1121,8 +1083,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:56.781251Z", - "start_time": "2024-10-08T21:00:56.776955Z" + "end_time": "2024-10-25T15:37:15.331503Z", + "start_time": "2024-10-25T15:37:15.326880Z" } }, "cell_type": "code", @@ -1134,7 +1096,7 @@ "# Ce dictionnaire doit être complété avec les infos saisies par l'utilisateur" ], "outputs": [], - "execution_count": 33 + "execution_count": 22 }, { "metadata": {}, @@ -1157,8 +1119,8 @@ "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:56.876202Z", - "start_time": "2024-10-08T21:00:56.868788Z" + "end_time": "2024-10-25T15:37:15.469187Z", + "start_time": "2024-10-25T15:37:15.463322Z" } }, "cell_type": "code", @@ -1183,18 +1145,18 @@ "\n", "\n", "\n", - "{'Python', 'Code Source', 'Scripting'}\n" + "{'Scripting', 'Python', 'Code Source'}\n" ] } ], - "execution_count": 34 + "execution_count": 23 }, { "metadata": { "trusted": false, "ExecuteTime": { - "end_time": "2024-10-08T21:00:57.000817Z", - "start_time": "2024-10-08T21:00:56.995307Z" + "end_time": "2024-10-25T15:37:15.521401Z", + "start_time": "2024-10-25T15:37:15.515910Z" } }, "cell_type": "code", @@ -1212,7 +1174,7 @@ ] } ], - "execution_count": 35 + "execution_count": 24 } ], "metadata": {