diff --git a/Notebooks/04_Les_fonctions_avec_parametres.ipynb b/Notebooks/04_Les_fonctions_avec_parametres.ipynb index 7494005f9d86fdb7883d6be6ed20dd6c220c2344..8beb50d610bdba6707509310990d7ca0311343bb 100644 --- a/Notebooks/04_Les_fonctions_avec_parametres.ipynb +++ b/Notebooks/04_Les_fonctions_avec_parametres.ipynb @@ -1,5 +1,18 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<div style=\"padding:20px;background-color:papayawhip;\" > \n", + "<h3 style=\"color:chocolate\"> <i class=\"fa fa-info\" aria-hidden=\"true\"> </i> Remarque introductive <i class=\"fa fa-info\" aria-hidden=\"true\"></h3> \n", + "<p> Ce fichier est fait pour être lu sur le site <a href=\"https://notebook.basthon.fr/\"><img src='https://notebook.basthon.fr/assets/efede5218c9087496f16.png' style=\"border: 0; display:inline; margin: 0 5px; height:30px\" alt=\"Basthon\"/></a>. <br>\n", + " \n", + "Si vous l'avez ouvert avec un autre programme, comme Jupyter notebook, vous riquez de rencontrer quelques bugs. <br>\n", + "Veuillez cliquez sur <a href=\"https://notebook.basthon.fr/\">ce lien</a> et y charger ce fichier à l'aide du bouton \"Ouvrir\" <i class=\"fa fa-folder\" aria-hidden=\"true\"> </i>\n", + "</p> </div> " + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -9,7 +22,7 @@ "Dans cette leçon, nous allons approfondir le concept de la fonction. Dans la leçon 3 sur les fonctions simples, nous avons vu la fonction comme une façon de donner un nom à une séquence d'instructions. Ici nous allons voir comment nous pouvons ajouter un ou plusieurs paramètres à une fonction. Nous allons voir que :\n", "\n", "- l'expression `def rect(d, e):` permet de définir une fonction avec deux paramètres,\n", - "- les paramètres `d, e` sont des variables locales valides uniquement à l'intérieur de la définition de fonction,\n", + "- les paramètres `d` et `e` sont des variables locales valides uniquement à l'intérieur de la définition de fonction,\n", "- ces paramètres prennent une valeur au moment de l'appel de la fonction avec `rect(50, 30)`.\n", "\n" ] @@ -42,7 +55,7 @@ "metadata": {}, "source": [ "<details>\n", - "<summary style=\"border-left:3px solid #3c763d; border-radius:2pt; width:100%; color:#3c763d; padding:6px; background-color: #dff0d8\"> \n", + "<summary style=\"border-left:3px solid #3c763d; border-radius:2pt; width:100%; color:#3c763d; padding:6px; background-color: #dff0d8\"> <i class=\"fa fa-angle-right\" aria-hidden=\"true\">\n", "Réponse\n", "</summary> \n", "\n", @@ -160,43 +173,6 @@ "Remarque: Le deuxième angle du losange est calculé." ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Exemple 2 : Le polygone**\n", - "\n", - "Essayez de comprendre le programme ci-dessous, puis exécutez le..." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from turtle import *\n", - "\n", - "def polygone(d, n): # paramètres (d, n)\n", - " for i in range(n):\n", - " forward(d)\n", - " left(360/n)\n", - "\n", - "polygone(100, 3) # triangle\n", - "polygone(100, 4) # carré\n", - "polygone(100, 5) # pentagon\n", - "\n", - "done()\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "On remarque que la fonction `polygone(d, n)` a comme paramètre la distance d'un côté et le nombre de sommets.\n", - "\n" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -247,76 +223,6 @@ "done()\n" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Positionner la maison\n", - "\n", - "!!! info Rappel\n", - "Au départ, la tortue se trouve au centre d'une zone rectangulaire appelée _canevas_. \n", - "\n", - "Ce rectangle a les propriétés suivantes :\n", - "\n", - "- l'origine (0, 0) se trouve au centre,\n", - "- l'axe horizontal x, s'étend de -300 à +300 (à droite),\n", - "- l'axe vertical y, s'étend de -200 à +200 (en haut).\n", - "!!!\n", - "\n", - "La fonction `goto(x, y)` permet de placer directement la tortue à la position de coordonnées `(x, y)`. On peut utiliser `goto(x, y)` pour positionner notre maison à un endroit précis.\n", - "\n", - "Pour désigner une position, nous utilisons la variable `p` (p pour position) qui représente le couple de coordonnées `[x, y]`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "<h3 style=\"color:teal;background-color:azure;\" > <i class=\"fa fa-pencil\" aria-hidden=\"true\"> </i> Exercice 3 </h3>Aujoutez deux autres maisons de taille différente.\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from turtle import *\n", - "\n", - "def maison(p , d):\n", - " goto(p) # aller à la position p\n", - " dot() # ajouter un marquer (dot)\n", - " down()\n", - " forward (1.41*d) # sol\n", - " left(90)\n", - " forward(d) # mur droit\n", - " left(45)\n", - " forward(d) # toit droit\n", - " left(90)\n", - " forward(d) # toit gauche\n", - " left(45)\n", - " forward(d) # mur gauche\n", - " left(90)\n", - " up()\n", - "\n", - "maison([0, 0], 50) # maison à la position (0, 0)\n", - "maison([-150, 50], 70) # maison à la position (-150, 50)\n", - "\n", - "done()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "!!! info Les listes\n", - "En Python les données peuvent être de plusieurs type. Par exemple, nous avons déjà rencontré le type nombre entier (`int`), nombre à virgule **flottante** (`float`) et chaînes de caractères (`str`).\n", - "\n", - "En python, le type `list` permet de définir des données composée d e plusieurs valeurs. Il suffit de mettre les valeurs, séparées par des virgules, entre des crochets.\n", - "!!!" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -341,15 +247,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"640\" height=\"480\" preserveaspectratio=\"xMidYMid meet\" viewbox=\"0 0 640 480\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_0\" attributename=\"opacity\" attributetype=\"CSS\" from=\"1\" to=\"1\" begin=\"0s\" dur=\"1ms\" fill=\"freeze\"></animate><g transform=\"translate(320 240)\"></g><g transform=\"translate(320 240)\"><line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"0\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_2\" attributename=\"x2\" attributetype=\"XML\" from=\"0\" to=\"0\" dur=\"1ms\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_1.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_1.end\" from=\"0\" to=\"0\" dur=\"1ms\" fill=\"freeze\"></animate></line><line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"0\" style=\"stroke: black;stroke-width: 1\" opacity=\"0\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_5\" attributename=\"x2\" attributetype=\"XML\" from=\"0\" to=\"0\" dur=\"1ms\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_4.end\"></animate></line><circle cx=\"0\" cy=\"0\" r=\"2.5\" fill=\"black\" style=\"display: none;\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_6\" attributename=\"display\" attributetype=\"CSS\" from=\"block\" to=\"block\" dur=\"1ms\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_5.end\"></animate></circle><line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"0\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_8\" attributename=\"x2\" attributetype=\"XML\" from=\"0\" to=\"98.69999999999999\" dur=\" 0.528s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_7.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_7.end\" from=\"0\" to=\"0\" dur=\" 0.528s\" fill=\"freeze\"></animate></line><line x1=\"98.69999999999999\" y1=\"0\" x2=\"98.69999999999999\" y2=\"0\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_10\" attributename=\"x2\" attributetype=\"XML\" from=\"98.69999999999999\" to=\"98.69999999999999\" dur=\" 0.375s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_9.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_9.end\" from=\"0\" to=\"-70\" dur=\" 0.375s\" fill=\"freeze\"></animate></line><line x1=\"98.69999999999999\" y1=\"-70\" x2=\"98.69999999999999\" y2=\"-70\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_12\" attributename=\"x2\" attributetype=\"XML\" from=\"98.69999999999999\" to=\"49.20252531694167\" dur=\" 0.375s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_11.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_11.end\" from=\"-70\" to=\"-119.49747468305833\" dur=\" 0.375s\" fill=\"freeze\"></animate></line><line x1=\"49.20252531694167\" y1=\"-119.49747468305833\" x2=\"49.20252531694167\" y2=\"-119.49747468305833\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_14\" attributename=\"x2\" attributetype=\"XML\" from=\"49.20252531694167\" to=\"-0.29494936611666844\" dur=\" 0.375s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_13.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_13.end\" from=\"-119.49747468305833\" to=\"-70\" dur=\" 0.375s\" fill=\"freeze\"></animate></line><line x1=\"-0.29494936611666844\" y1=\"-70\" x2=\"-0.29494936611666844\" y2=\"-70\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_16\" attributename=\"x2\" attributetype=\"XML\" from=\"-0.29494936611666844\" to=\"-0.2949493661166813\" dur=\" 0.375s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_15.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_15.end\" from=\"-70\" to=\"0\" dur=\" 0.375s\" fill=\"freeze\"></animate></line><polygon points=\"0,0 98.69999999999999,-0.0 98.69999999999999,-70.0 49.20252531694167,-119.49747468305833 -0.29494936611666844,-70.0 -0.2949493661166813,-0.0\" style=\"display: none;fill: lightblue;stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_18\" attributename=\"display\" attributetype=\"CSS\" from=\"block\" to=\"block\" dur=\"1ms\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_17.end\"></animate></polygon><line x1=\"-0.2949493661166813\" y1=\"0\" x2=\"-0.2949493661166813\" y2=\"0\" style=\"stroke: black;stroke-width: 1\" opacity=\"0\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_19\" attributename=\"x2\" attributetype=\"XML\" from=\"-0.2949493661166813\" to=\"150\" dur=\" 0.965s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_18.end\"></animate></line><circle cx=\"150\" cy=\"-30\" r=\"2.5\" fill=\"black\" style=\"display: none;\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_20\" attributename=\"display\" attributetype=\"CSS\" from=\"block\" to=\"block\" dur=\"1ms\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_19.end\"></animate></circle><line x1=\"150\" y1=\"-30\" x2=\"150\" y2=\"-30\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_22\" attributename=\"x2\" attributetype=\"XML\" from=\"150\" to=\"220.5\" dur=\" 0.377s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_21.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_21.end\" from=\"-30\" to=\"-29.999999999999982\" dur=\" 0.377s\" fill=\"freeze\"></animate></line><line x1=\"220.5\" y1=\"-29.999999999999982\" x2=\"220.5\" y2=\"-29.999999999999982\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_24\" attributename=\"x2\" attributetype=\"XML\" from=\"220.5\" to=\"220.50000000000003\" dur=\" 0.268s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_23.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_23.end\" from=\"-29.999999999999982\" to=\"-79.99999999999999\" dur=\" 0.268s\" fill=\"freeze\"></animate></line><line x1=\"220.50000000000003\" y1=\"-79.99999999999999\" x2=\"220.50000000000003\" y2=\"-79.99999999999999\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_26\" attributename=\"x2\" attributetype=\"XML\" from=\"220.50000000000003\" to=\"185.14466094067262\" dur=\" 0.268s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_25.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_25.end\" from=\"-79.99999999999999\" to=\"-115.35533905932735\" dur=\" 0.268s\" fill=\"freeze\"></animate></line><line x1=\"185.14466094067262\" y1=\"-115.35533905932735\" x2=\"185.14466094067262\" y2=\"-115.35533905932735\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_28\" attributename=\"x2\" attributetype=\"XML\" from=\"185.14466094067262\" to=\"149.78932188134527\" dur=\" 0.268s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_27.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_27.end\" from=\"-115.35533905932735\" to=\"-79.99999999999996\" dur=\" 0.268s\" fill=\"freeze\"></animate></line><line x1=\"149.78932188134527\" y1=\"-79.99999999999996\" x2=\"149.78932188134527\" y2=\"-79.99999999999996\" style=\"stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_30\" attributename=\"x2\" attributetype=\"XML\" from=\"149.78932188134527\" to=\"149.78932188134524\" dur=\" 0.268s\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_29.end\"></animate><animate attributename=\"y2\" attributetype=\"XML\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_29.end\" from=\"-79.99999999999996\" to=\"-29.999999999999957\" dur=\" 0.268s\" fill=\"freeze\"></animate></line><polygon points=\"150,-30 220.5,-29.999999999999982 220.50000000000003,-79.99999999999999 185.14466094067262,-115.35533905932735 149.78932188134527,-79.99999999999996 149.78932188134524,-29.999999999999957\" style=\"display: none;fill: yellow;stroke: black;stroke-width: 1\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_32\" attributename=\"display\" attributetype=\"CSS\" from=\"block\" to=\"block\" dur=\"1ms\" fill=\"freeze\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_31.end\"></animate></polygon></g><g transform=\"translate(320 240)\"></g><g transform=\"translate(320 240)\"><polygon points=\"0,16 -2,14 -1,10 -4,7 -7,9 -9,8 -6,5 -7,1 -5,-3 -8,-6 -6,-8 -4,-5 0,-7 4,-5 6,-8 8,-6 5,-3 7,1 6,5 9,8 7,9 4,7 1,10 2,14\" stroke=\"black\" fill=\"black\" stroke-width=\"1\" opacity=\"0\"><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_1\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_0.end\" dur=\"1ms\" fill=\"freeze\" attributename=\"opacity\" attributetype=\"XML\" from=\"0\" to=\"1\"></animate><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_2.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_3\" type=\"rotate\" from=\"0,0,0\" to=\"0.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_2.end\" dur=\"1ms\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_3.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_4\" type=\"rotate\" from=\"-90.0,0,0\" to=\"-90.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_3.end\" dur=\"1ms\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_4.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"0.0,-0.0\" to=\"0,0\" dur=\"1ms\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_4.end\" fill=\"freeze\"></animateMotion><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_7\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_6.end\" dur=\"1ms\" fill=\"freeze\" attributename=\"fill\" attributetype=\"XML\" from=\"black\" to=\"lightblue\"></animate><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_7.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"0,0\" to=\"98.69999999999999,-0.0\" dur=\" 0.528s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_7.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_8.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_9\" type=\"rotate\" from=\"-90.0,0,0\" to=\"-180.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_8.end\" dur=\" 0.083s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_9.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"98.69999999999999,-0.0\" to=\"98.69999999999999,-70.0\" dur=\" 0.375s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_9.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_10.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_11\" type=\"rotate\" from=\"-180.0,0,0\" to=\"-225.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_10.end\" dur=\" 0.042s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_11.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"98.69999999999999,-70.0\" to=\"49.20252531694167,-119.49747468305833\" dur=\" 0.375s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_11.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_12.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_13\" type=\"rotate\" from=\"-225.0,0,0\" to=\"-315.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_12.end\" dur=\" 0.083s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_13.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"49.20252531694167,-119.49747468305833\" to=\"-0.29494936611666844,-70.0\" dur=\" 0.375s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_13.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_14.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_15\" type=\"rotate\" from=\"-315.0,0,0\" to=\"-360.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_14.end\" dur=\" 0.042s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_15.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"-0.29494936611666844,-70.0\" to=\"-0.2949493661166813,-0.0\" dur=\" 0.375s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_15.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_16.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_17\" type=\"rotate\" from=\"-360.0,0,0\" to=\"-450.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_16.end\" dur=\" 0.083s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_18.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"-0.2949493661166813,-0.0\" to=\"150,-30\" dur=\" 0.965s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_18.end\" fill=\"freeze\"></animateMotion><animate id=\"af_b32f4a9fb3d74061922d432cbf99248d_21\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_20.end\" dur=\"1ms\" fill=\"freeze\" attributename=\"fill\" attributetype=\"XML\" from=\"lightblue\" to=\"yellow\"></animate><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_21.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"150,-30\" to=\"220.5,-29.999999999999982\" dur=\" 0.377s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_21.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_22.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_23\" type=\"rotate\" from=\"-450.0,0,0\" to=\"-540.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_22.end\" dur=\" 0.083s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_23.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"220.5,-29.999999999999982\" to=\"220.50000000000003,-79.99999999999999\" dur=\" 0.268s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_23.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_24.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_25\" type=\"rotate\" from=\"-540.0,0,0\" to=\"-585.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_24.end\" dur=\" 0.042s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_25.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"220.50000000000003,-79.99999999999999\" to=\"185.14466094067262,-115.35533905932735\" dur=\" 0.268s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_25.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_26.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_27\" type=\"rotate\" from=\"-585.0,0,0\" to=\"-675.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_26.end\" dur=\" 0.083s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_27.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"185.14466094067262,-115.35533905932735\" to=\"149.78932188134527,-79.99999999999996\" dur=\" 0.268s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_27.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_28.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_29\" type=\"rotate\" from=\"-675.0,0,0\" to=\"-720.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_28.end\" dur=\" 0.042s\" fill=\"freeze\"></animateTransform><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_29.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateMotion from=\"149.78932188134527,-79.99999999999996\" to=\"149.78932188134524,-29.999999999999957\" dur=\" 0.268s\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_29.end\" fill=\"freeze\"></animateMotion><animateMotion begin=\"af_b32f4a9fb3d74061922d432cbf99248d_30.end\" dur=\"1ms\" fill=\"remove\"></animateMotion><animateTransform attributename=\"transform\" id=\"af_b32f4a9fb3d74061922d432cbf99248d_31\" type=\"rotate\" from=\"-720.0,0,0\" to=\"-810.0,0,0\" begin=\"af_b32f4a9fb3d74061922d432cbf99248d_30.end\" dur=\" 0.083s\" fill=\"freeze\"></animateTransform></polygon></g></svg>" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from turtle import *\n", "up()\n", "\n", - "def maison(p, d, c):\n", - " goto(p)\n", + "def maison(d, c):\n", " dot()\n", " down()\n", " fillcolor(c)\n", @@ -367,8 +282,10 @@ " end_fill()\n", " up()\n", "\n", - "maison([0, 0], 70, 'lightblue')\n", - "maison([150, 30], 50, 'yellow')\n", + "goto(0,0)\n", + "maison(70, 'lightblue')\n", + "goto(150, 30)\n", + "maison(50, 'yellow')\n", "\n", "done()\n" ] @@ -613,74 +530,6 @@ "done()\n" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Nommer une variable\n", - "\n", - "Pour nommer une variable, on utilise les caractères suivants :\n", - "\n", - "- lettres (`a...z` et `A...Z`),\n", - "- chiffres (`0...9`),\n", - "- le tiret bas (`_`).\n", - "\n", - "Le nom de variable :\n", - "\n", - "- est sensible aux majuscules/minuscules (`BUS` et `bus` sont des noms de variables différents),\n", - "- ne peut pas commencer avec un chiffre,\n", - "- ne doit pas consister d'un mot-clé (`def`, `for`, `in`, `from`, ...),\n", - "\n", - "Par exemplee, les noms de variables suivantes sont valides : \n", - " `a2`, `_a`, `speed`, `pos_x`, `POS_X`,\n", - "\n", - "tandis que ceux là ne le sont pas : `2a`, `def`, `pos x`.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "<h3 style=\"color:chocolate;background-color:papayawhip;\" > <i class=\"fa fa-question\" aria-hidden=\"true\"> </i> Quizz </h3> \n", - " \n", - "```\n", - "Lesquels des noms de variable sont valides ?\n", - "\n", - "A) var 2\n", - "B) var2\n", - "C) 2var\n", - "D) IF\n", - "```" - ] - }, - { - "cell_type": "raw", - "metadata": {}, - "source": [ - "Votre réponse: " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "<details>\n", - "<summary style=\"border-left:3px solid #3c763d; border-radius:2pt; width:100%; color:#3c763d; padding:6px; background-color: #dff0d8\"> \n", - "Réponse\n", - "</summary> \n", - "\n", - "<div style=\"border-left:3px solid #3c763d; border-radius:2pt; color:#3c763d; padding:6px; background-color: #eff0e8\">\n", - "\n", - "B) `var2`\n", - " \n", - "D) `IF` serait valable car différent du mot clé `if` (rappel : Python est sensible aux majuscules/minuscules)\n", - " \n", - "Les deux autres ne sont pas valables car `var 2` contient une espace et `2var` commence par un chiffre.\n", - " \n", - "</div>\n", - "</details>" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -722,37 +571,7 @@ "source": [ "<h3 style=\"color:teal;background-color:azure;\" > <i class=\"fa fa-pencil\" aria-hidden=\"true\"> </i> Exercice 9 </h3>\n", "\n", - "1. Testez le programme suivant (voir plus bas pour tester) :\n", - "\n", - "```Python\n", - "from turtle import *\n", - "\n", - "# pour être à gauche du canevas\n", - "backward(250)\n", - "\n", - "# Code à factoriser\n", - "for k in range(3):\n", - " forward(30)\n", - " right(120)\n", - "forward(30)\n", - "for k in range(3):\n", - " forward(60)\n", - " right(120)\n", - "forward(60)\n", - "for k in range(3):\n", - " forward(90)\n", - " right(120)\n", - "forward(90)\n", - "for k in range(3):\n", - " forward(120)\n", - " right(120)\n", - "forward(120)\n", - "for k in range(3):\n", - " forward(150)\n", - " right(120)\n", - "\n", - "done()\n", - "```\n", + "1. Testez le programme suivant ci-dessous.\n", "2. Définissez une fonction `triangle(l)`, qui permet de tracer des triangles équilatéraux de longueur lg, et utilisez-là pour réduire le nombre d’instructions du programme. \n", "\n", "**NB**: Le nombre d'instructions du programme doit être au moins divisé par 2.\n" @@ -1056,13 +875,6 @@ "Ce document est une adaptation d'un ressource pédagogique tiré du catalogue modulo https://modulo-info.ch/. Il est sous license Creative Commons [BY-NC-SA](https://creativecommons.org/licenses/?lang=fr)\n", "" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {