{"id":489,"date":"2022-02-06T10:06:34","date_gmt":"2022-02-06T09:06:34","guid":{"rendered":"http:\/\/yb-isn.fr\/2021\/nsi\/?p=489"},"modified":"2022-02-07T22:10:34","modified_gmt":"2022-02-07T21:10:34","slug":"tuples-et-dictionnaires-en-python","status":"publish","type":"post","link":"http:\/\/yb-isn.fr\/2021\/nsi\/?p=489","title":{"rendered":"Collection d&rsquo;objets en python"},"content":{"rendered":"<p><!--more--><\/p>\n\n\n<p>Travailler \u00e0 partir des exemples propos\u00e9s sur w3scool.Vous garderez une trace de votre travail sur un ou plusieurs notebooks google colaboratory accessibles depuis votre blog.<\/p>\n\n\n\n<p>Travail pr\u00e9liminaire : codez une fonction qui prend pour argument un jour de la semaine en anglais<\/p>\n\n\n\n<p>La fonction doit renvoyer le jour de la semaine en Fran\u00e7ais.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-1024x175.png\" alt=\"\" class=\"wp-image-497\" width=\"512\" height=\"88\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-1024x175.png 1024w, http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-300x51.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-768x131.png 768w, http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-1200x207.png 1200w, http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image.png 1213w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/figure>\n\n\n<div class=\"container theme1\" style=\"width:100%; height:auto\"><ul class=\"responsive-accordion responsive-accordion-default bm-larger\"><li><div class=\"responsive-accordion-head\" style=\"background-color:\"><span style=\"color:;font-size:15px\">Corrig\u00e9: traducteur de jours<\/span><i class=\"fa fa-chevron-down responsive-accordion-plus fa-fw\"><\/i><i class=\"fa fa-chevron-up responsive-accordion-minus fa-fw\"><\/i><\/div><div class=\"responsive-accordion-panel\"style=\"background-color:;padding:12px;color:;font-size:14px\"><p><strong>Une solution \u00e0 \u00e9viter<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def dayJours(day):\r\n    if day=='Monday':\r\n        return 'Lundi'\r\n    if day=='Tuesday':\r\n        return 'Mardi'\r\n    if day=='Wednesday':\r\n        return 'Mercredi'\r\n    if day=='Thursday':\r\n        return 'Jeudi'\r\n    if day=='Friday':\r\n        return 'Vendredi'\r\n    if day=='Saturday':\r\n        return 'Samedi'\r\n    if day=='Sunday':\r\n        return 'Dimanche'<\/pre>\n<p><strong>A \u00e9viter aussi<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def dayJours1(day):\r\n    jour='erreur'\r\n    if day=='Monday':\r\n        jour= 'Lundi'\r\n    if day=='Tuesday':\r\n        jour= 'Mardi'\r\n    if day=='Wednesday':\r\n        jour=  'Mercredi'\r\n    if day=='Thursday':\r\n        jour= 'Jeudi'\r\n    if day=='Friday':\r\n        jour= 'Vendredi'\r\n    if day=='Saturday':\r\n        jour=  'Samedi'\r\n    if day=='Sunday':\r\n        jour= 'Dimanche'\r\n    return jour<\/pre>\n<p><strong>Une solution attendue<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">jours=[\"Lundi\",\"Mardi\",\"Mercredi\",\"Jeudi\",\"Vendredi\",\"Samedi\",\"Dimanche\"]\r\ndays=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday']\r\n\r\ndef dayJour1(day):\r\n    for i in range(7):\r\n        if day==days[i]:\r\n            return jours[i]<\/pre>\n<p><strong>Une autre solution possible en attendant d'apprendre \u00e0 utiliser les dictionnaires.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">jours=[\"Lundi\",\"Mardi\",\"Mercredi\",\"Jeudi\",\"Vendredi\",\"Samedi\",\"Dimanche\"]\r\ndays=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday']\r\n\r\ndef dayJour(day):\r\n    i=days.index(day)\r\n    return jours[i]<\/pre>\n<p>\u00a0<\/p>\n<\/div><\/li><\/ul><\/div>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-2-1024x392.png\" alt=\"\" class=\"wp-image-504\" width=\"512\" height=\"196\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-2-1024x392.png 1024w, http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-2-300x115.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-2-768x294.png 768w, http:\/\/yb-isn.fr\/2021\/nsi\/wp-content\/uploads\/2022\/02\/image-2.png 1493w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/figure>\n\n\n\n<p>Reproduire et compl\u00e9ter le tableau au fur et \u00e0 mesure<\/p>\n\n\n\n<p>Les&nbsp;<strong>listes<\/strong>, les&nbsp;<strong>dictionnaires<\/strong>&nbsp;et les&nbsp;<strong>tuples<\/strong>&nbsp;sont des objets qui peuvent contenir des collections d&rsquo;autres objets.&nbsp;<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\">Les Tup<strong>les<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.w3schools.com\/python\/python_tuples.asp\">https:\/\/www.w3schools.com\/python\/python_tuples.asp<\/a><\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\">Les dictionnaires<\/p>\n\n\n\n<p><a href=\"https:\/\/www.w3schools.com\/python\/python_dictionaries.asp\">https:\/\/www.w3schools.com\/python\/python_dictionaries.asp<\/a><\/p>\n\n\n\n<p>Reprendre le travail pr\u00e9liminaire en utilisant un dictionnaire<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\">Les listes python (rappels si n\u00e9cessaire)<\/p>\n\n\n\n<p><a href=\"https:\/\/www.w3schools.com\/python\/python_lists.asp\">https:\/\/www.w3schools.com\/python\/python_lists.asp<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":490,"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\/489"}],"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=489"}],"version-history":[{"count":20,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts\/489\/revisions"}],"predecessor-version":[{"id":845,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/posts\/489\/revisions\/845"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=\/wp\/v2\/media\/490"}],"wp:attachment":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=489"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}