{"id":40,"date":"2021-09-11T21:26:34","date_gmt":"2021-09-11T19:26:34","guid":{"rendered":"http:\/\/yb-isn.fr\/2021\/nsi\/?p=40"},"modified":"2021-10-01T22:58:11","modified_gmt":"2021-10-01T20:58:11","slug":"python-les-variables","status":"publish","type":"post","link":"http:\/\/yb-isn.fr\/2021\/nsi\/?p=40","title":{"rendered":"Python: Les variables"},"content":{"rendered":"<p><!--more--><\/p>\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\">1) G\u00e9n\u00e9ralit\u00e9s<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\">Une\nvariable est une \u00e9tiquette permettant d\u2019identifier une zone de la m\u00e9moire\nstockant une valeur qui lui a \u00e9t\u00e9 affect\u00e9e. <\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\">Une variable donn\u00e9e a&nbsp;:<\/p>\n\n\n\n<ul class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><li>un type qui d\u00e9pend de la nature de la valeur stock\u00e9e (typage dynamique)<\/li><\/ul>\n\n\n\n<ul class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><li>Le nom doit respecter certaines r\u00e8gles&nbsp;:<\/li><\/ul>\n\n\n\n<ul class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><li>Une taille en m\u00e9moire (nombre de bit ou d\u2019octets. Python g\u00e8re la m\u00e9moire pour vous)<\/li><\/ul>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\">Pour un nom de variable :<\/p>\n\n\n\n<ul class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><li>On ne commence pas par un chiffre<\/li><\/ul>\n\n\n\n<ul class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><li>On peut utiliser des lettres minuscules , MAJUSCULES&nbsp;, underscore_ et chiffres<\/li><\/ul>\n\n\n\n<ul class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><li>Les mots r\u00e9serv\u00e9s ne sont pas autoris\u00e9s (voir coloration synthaxique) <\/li><\/ul>\n\n\n\n<ul class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><li>On utilise  si possible l\u2019anglais<\/li><\/ul>\n\n\n\n<p class=\"has-small-font-size\">Nous allons \u00e9tudier 4 types de variables&nbsp;: <strong>int , float ,bool , str<\/strong><\/p>\n\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\">2) Les nombres entiers<\/p>\n\n\n\n<p>Effectuer vos propres tests dans une console python (thonny par exemple) ou dans un notebook<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-14.png\" alt=\"\" class=\"wp-image-74\"\/><\/figure>\n\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\">3) Les nombres d\u00e9cimaux<\/p>\n\n\n\n<p> Effectuer vos propres tests dans une console python (thonny par exemple) ou dans un notebook <\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><strong>La virgule d\u2019un nombre d\u00e9cimal se note avec un point en python.<\/strong><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-small-font-size\"><strong>D\u00e9clarez une variable en lui affectant une valeur d\u00e9cimale puis rechercher\nson type.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-15.png\" alt=\"\" class=\"wp-image-78\"\/><\/figure>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\"><strong>Les puissance de 10 se notent avec e ou E<\/strong><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-small-font-size\"><strong>Le rayon de la terre est \u00e9gal \u00e0 6380km. D\u00e9clarez une variable pour lui\naffecter le rayon&nbsp; de la terre en\nnotation scientifique en m.<\/strong><strong>Afficher la valeur ainsi que son\ntype<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-16-1.png\" alt=\"\" class=\"wp-image-86\"\/><\/figure>\n\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\">4) Les chaines de caract\u00e8res<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\">Pour enregistrer une chaine de caract\u00e8res dans une variable il faut utiliser des guillemets (\u00ab&nbsp;) ou des apostrophes (\u2018)<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\">Si la cha\u00eene comporte une apostrophe il faut utiliser des guillemets.  On peut aussi forcer l\u2019affichage de l\u2019apostrophe(\u2018) en la rempla\u00e7ant par (\\\u2019) dans la cha\u00eene .<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-17.png\" alt=\"\" class=\"wp-image-90\"\/><\/figure>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\">Une variable r\u00e9f\u00e9ren\u00e7ant une\ncha\u00eene de caract\u00e8res est de type <strong>str<\/strong><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-small-font-size\"> Effectuer vos propres tests dans une console python (thonny par exemple) ou dans un notebook <\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-small-font-size\">exemple de tests<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-18.png\" alt=\"\" class=\"wp-image-91\"\/><\/figure>\n\n\n\n<p class=\"has-very-light-gray-background-color has-background has-medium-font-size\">5) Un pas vers la logique binaire<\/p>\n\n\n\n<p class=\"has-small-font-size\">Si vous tapez <strong>False<\/strong> ou <strong>True<\/strong> dans la console python vous remarquez d\u2019apr\u00e8s la coloration que ces mots sont r\u00e9serv\u00e9s. Il en est de m\u00eame pour <strong>not or<\/strong> et <strong>and.<\/strong>Il en est de m\u00eame pour <strong>not or<\/strong> et <strong>and.<\/strong><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-small-font-size\">D\u00e9clarez une variable etat en lui affectant la valeur True ou False puis rechercher son type<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-20.png\" alt=\"\" class=\"wp-image-98\"\/><\/figure>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-small-font-size\">etat est une variable bool\u00e9enne qui ne peut prendre que deux valeurs True ou False c\u2019est-\u00e0-dire vrai ou faux.<\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-small-font-size\"><strong>no<\/strong>t est un op\u00e9rateur . Remplir le tableau ci-dessous.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-19.png\" alt=\"\" class=\"wp-image-97\"\/><\/figure>\n\n\n\n<p class=\"has-black-color has-text-color has-small-font-size\">\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCompl\u00e9tez\nle tableau ci-dessous\n\n\n\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-22.png\" alt=\"\" class=\"wp-image-101\"\/><\/figure>\n\n\n\n<p class=\"has-black-color has-text-color has-small-font-size\">or signifie ou. Est ce un ou inclusif ou exclusif&nbsp;?<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-23.png\" alt=\"\" class=\"wp-image-102\"\/><figcaption>Il s&rsquo;agit donc d&rsquo;un ou inclusif.<\/figcaption><\/figure>\n\n\n\n<p>Vous retrouverez les exemples sur mon <a href=\"https:\/\/colab.research.google.com\/drive\/1GtJuQTn7c0rnkYpcpSHK0rksqLSotGba?usp=sharing\">Colaboratory<\/a><\/p>\n\n\n\n<p>Vous pouvez utiliser le bloc enlighter pour pr\u00e9senter du code sur votre blog ou donner le lien partag\u00e9 vers votre colaboratory<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"godzilla\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#table de verit\u00e9 du ou inclusif\nprint(\"False or False  |\",False or False)\nprint(\"True  or False  |\",True or False)\nprint(\"True  or True   |\",True or True)\nprint(\"False or True   |\",False or True)<\/pre>\n\n\n\n<p>L&rsquo;affectation des variables peut \u00eatre obtenue par une entr\u00e9e clavier.<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">La fonction input() &nbsp;permet de lire une ligne saisie au clavier et de la stocker dans une variable lorsque la touche entr\u00e9e est frapp\u00e9e.<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">Elle accepte un argument optionnel qui permet d\u2019afficher une chaine de caract\u00e8res \u00e0 l&rsquo;utilisateur.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/activite.png\" alt=\"\" class=\"wp-image-23\"\/><\/figure>\n\n\n\n<p class=\"has-black-color has-text-color\">\u00e9crire un programme qui calcule l&rsquo;imc d&rsquo;un adulte<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/num\/wp-content\/uploads\/2021\/03\/imc-1-768x384-300x150.png\" alt=\"\" class=\"wp-image-590\"\/><figcaption>imc=masse\/taille<sup>2<\/sup><\/figcaption><\/figure>\n\n\n\n<p>masse en kg et taille en m<\/p>\n\n\n\n<p class=\"has-pale-pink-background-color has-background has-medium-font-size\">R\u00e9sum\u00e9<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"http:\/\/yb-isn.fr\/nsi2019\/wp-content\/uploads\/2019\/09\/Sans-titre-24.png\" alt=\"\" class=\"wp-image-106\"\/><\/figure>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\">Attention : la variable obtenue par une entr\u00e9e clavier \u00e0 l&rsquo;aide de la fonction input() est de type str m\u00eame si la saisie effectu\u00e9e est un nombre<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":175,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts\/40"}],"collection":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=40"}],"version-history":[{"count":22,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":172,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions\/172"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/media\/175"}],"wp:attachment":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}