1540 lines
241 KiB
HTML
1540 lines
241 KiB
HTML
|
<!DOCTYPE html>
|
|||
|
<html>
|
|||
|
<head>
|
|||
|
|
|||
|
<meta charset="utf-8" />
|
|||
|
<title>Projets Python</title>
|
|||
|
|
|||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
|
|||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
|
|||
|
|
|||
|
<style type="text/css">
|
|||
|
/*!
|
|||
|
*
|
|||
|
* Twitter Bootstrap
|
|||
|
*
|
|||
|
*//*! normalize.css v3.0.2 | MIT License | git.io/normalize */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}/*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */@media print{*,*:before,*:after{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}a[href^="#"]:after,a[href^="javascript:"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}select{background:#fff !important}.navbar{display:none}.btn>.caret,.dropup>.btn>.caret{border-top-color:#000 !important}.label{border:1px solid #000}.table{border-collapse:collapse !important}.table td,.table th{background-color:#fff !important}.table-bordered th,.table-bordered td{border:1px solid #ddd !important}}@font-face{font-family:'Glyphicons Halflings';src:url('../components/bootstrap/fonts/glyphicons-halflings-regular.eot');src:url('../components/bootstrap/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),url('../components/bootstrap/fonts/glyphicons-halflings-regular.woff') format('woff'),url('../components/bootstrap/fonts/glyphicons-halflings-regular.ttf') format('truetype'),url('../components/bootstrap/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg')}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:normal;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.glyphicon-asterisk:before{content:"\2a"}.glyphicon-plus:before{content:"\2b"}.glyphicon-euro:before,.glyphicon-eur:before{content:"\20ac"}.glyphicon-minus:before{content:"\2212"}.glyphicon-cloud:before{content:"\2601"}.glyphicon-envelope:before{content:"\2709"}.glyphicon-pencil:before{content:"\270f"}.glyphicon-glass:before{content:"\e001"}.glyphicon-music:before{content:"\e002"}.glyphicon-search:before{content:
|
|||
|
*
|
|||
|
* Font Awesome
|
|||
|
*
|
|||
|
*//*!
|
|||
|
* Font Awesome 4.3.0 by @davegandy - http://fontawesome.io - @fontawesome
|
|||
|
* License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License)
|
|||
|
*/@font-face{font-family:'FontAwesome';src:url('../components/font-awesome/fonts/fontawesome-webfont.eot?v=4.3.0');src:url('../components/font-awesome/fonts/fontawesome-webfont.eot?#iefix&v=4.3.0') format('embedded-opentype'),url('../components/font-awesome/fonts/fontawesome-webfont.woff2?v=4.3.0') format('woff2'),url('../components/font-awesome/fonts/fontawesome-webfont.woff?v=4.3.0') format('woff'),url('../components/font-awesome/fonts/fontawesome-webfont.ttf?v=4.3.0') format('truetype'),url('../components/font-awesome/fonts/fontawesome-webfont.svg?v=4.3.0#fontawesomeregular') format('svg');font-weight:normal;font-style:normal}.fa{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0)}.fa-lg{font-size:1.33333333em;line-height:.75em;vertical-align:-15%}.fa-2x{font-size:2em}.fa-3x{font-size:3em}.fa-4x{font-size:4em}.fa-5x{font-size:5em}.fa-fw{width:1.28571429em;text-align:center}.fa-ul{padding-left:0;margin-left:2.14285714em;list-style-type:none}.fa-ul>li{position:relative}.fa-li{position:absolute;left:-2.14285714em;width:2.14285714em;top:.14285714em;text-align:center}.fa-li.fa-lg{left:-1.85714286em}.fa-border{padding:.2em .25em .15em;border:solid .08em #eee;border-radius:.1em}.pull-right{float:right}.pull-left{float:left}.fa.pull-left{margin-right:.3em}.fa.pull-right{margin-left:.3em}.fa-spin{-webkit-animation:fa-spin 2s infinite linear;animation:fa-spin 2s infinite linear}.fa-pulse{-webkit-animation:fa-spin 1s infinite steps(8);animation:fa-spin 1s infinite steps(8)}@-webkit-keyframes fa-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}}@keyframes fa-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}}.fa-rotate-90{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=1);-webkit-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg)}.fa-rotate-180{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=2);-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg)}.fa-rotate-270{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=3);-webkit-transform:rotate(270deg);-ms-transform:rotate(270deg);transform:rotate(270deg)}.fa-flip-horizontal{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);-webkit-transform:scale(-1, 1);-ms-transform:scale(-1, 1);transform:scale(-1, 1)}.fa-flip-vertical{filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1);-webkit-transform:scale(1, -1);-ms-transform:scale(1, -1);transform:scale(1, -1)}:root .fa-rotate-90,:root .fa-rotate-180,:root .fa-rotate-270,:root .fa-flip-horizontal,:root .fa-flip-vertical{filter:none}.fa-stack{position:relative;display:inline-block;width:2em;height:2em;line-height:2em;vertical-align:middle}.fa-stack-1x,.fa-stack-2x{position:absolute;left:0;width:100%;text-align:center}.fa-stack-1x{line-height:inherit}.fa-stack-2x{font-size:2em}.fa-inverse{color:#fff}.fa-glass:before{content:"\f000"}.fa-music:before{content:"\f001"}.fa-search:before{content:"\f002"}.fa-envelope-o:before{content:"\f003"}.fa-heart:before{content:"\f004"}.fa-star:before{content:"\f005"}.fa-star-o:before{content:"\f006"}.fa-user:before{content:"\f007"}.fa-film:before{content:"\f008"}.fa-th-large:before{content:"\f009"}.fa-th:before{content:"\f00a"}.fa-th-list:before{content:"\f00b"}.fa-check:before{content:"\f00c"}.fa-remove:before,.fa-close:before,.fa-times:before{content:"\f00d"}.fa-search-plus:before{content:"\f00e"}.fa-search-minus:before{content:"\f010"}.fa-power-off:before{content:"\f011"}.fa-signal:before{content:"\f012"}.fa-gear:before,.fa-cog:before{content:"\f013"}.fa-trash-o:before{content:"\f014"}.fa-home:before{content:"\f015"}.fa-file-o:before{content:"\f016"}.fa-clock-o:before{content:"\f017"}.fa-road:before{content:"\f018"}.fa-download:before{content:"\f019"}.fa-arrow-circle-o-down:befo
|
|||
|
*
|
|||
|
* IPython base
|
|||
|
*
|
|||
|
*/.modal.fade .modal-dialog{-webkit-transform:translate(0, 0);-ms-transform:translate(0, 0);-o-transform:translate(0, 0);transform:translate(0, 0)}code{color:#000}pre{font-size:inherit;line-height:inherit}label{font-weight:normal}.border-box-sizing{box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box}.corner-all{border-radius:2px}.no-padding{padding:0}.hbox{display:-webkit-box;-webkit-box-orient:horizontal;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:horizontal;-moz-box-align:stretch;display:box;box-orient:horizontal;box-align:stretch;display:flex;flex-direction:row;align-items:stretch}.hbox>*{-webkit-box-flex:0;-moz-box-flex:0;box-flex:0;flex:none}.vbox{display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;display:flex;flex-direction:column;align-items:stretch}.vbox>*{-webkit-box-flex:0;-moz-box-flex:0;box-flex:0;flex:none}.hbox.reverse,.vbox.reverse,.reverse{-webkit-box-direction:reverse;-moz-box-direction:reverse;box-direction:reverse;flex-direction:row-reverse}.hbox.box-flex0,.vbox.box-flex0,.box-flex0{-webkit-box-flex:0;-moz-box-flex:0;box-flex:0;flex:none;width:auto}.hbox.box-flex1,.vbox.box-flex1,.box-flex1{-webkit-box-flex:1;-moz-box-flex:1;box-flex:1;flex:1}.hbox.box-flex,.vbox.box-flex,.box-flex{-webkit-box-flex:1;-moz-box-flex:1;box-flex:1;flex:1}.hbox.box-flex2,.vbox.box-flex2,.box-flex2{-webkit-box-flex:2;-moz-box-flex:2;box-flex:2;flex:2}.box-group1{-webkit-box-flex-group:1;-moz-box-flex-group:1;box-flex-group:1}.box-group2{-webkit-box-flex-group:2;-moz-box-flex-group:2;box-flex-group:2}.hbox.start,.vbox.start,.start{-webkit-box-pack:start;-moz-box-pack:start;box-pack:start;justify-content:flex-start}.hbox.end,.vbox.end,.end{-webkit-box-pack:end;-moz-box-pack:end;box-pack:end;justify-content:flex-end}.hbox.center,.vbox.center,.center{-webkit-box-pack:center;-moz-box-pack:center;box-pack:center;justify-content:center}.hbox.baseline,.vbox.baseline,.baseline{-webkit-box-pack:baseline;-moz-box-pack:baseline;box-pack:baseline;justify-content:baseline}.hbox.stretch,.vbox.stretch,.stretch{-webkit-box-pack:stretch;-moz-box-pack:stretch;box-pack:stretch;justify-content:stretch}.hbox.align-start,.vbox.align-start,.align-start{-webkit-box-align:start;-moz-box-align:start;box-align:start;align-items:flex-start}.hbox.align-end,.vbox.align-end,.align-end{-webkit-box-align:end;-moz-box-align:end;box-align:end;align-items:flex-end}.hbox.align-center,.vbox.align-center,.align-center{-webkit-box-align:center;-moz-box-align:center;box-align:center;align-items:center}.hbox.align-baseline,.vbox.align-baseline,.align-baseline{-webkit-box-align:baseline;-moz-box-align:baseline;box-align:baseline;align-items:baseline}.hbox.align-stretch,.vbox.align-stretch,.align-stretch{-webkit-box-align:stretch;-moz-box-align:stretch;box-align:stretch;align-items:stretch}div.error{margin:2em;text-align:center}div.error>h1{font-size:500%;line-height:normal}div.error>p{font-size:200%;line-height:normal}div.traceback-wrapper{text-align:left;max-width:800px;margin:auto}body{background-color:#fff;position:absolute;left:0;right:0;top:0;bottom:0;overflow:visible}#header{display:none;background-color:#fff;position:relative;z-index:100}#header #header-container{padding-bottom:5px;padding-top:5px;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box}#header .header-bar{width:100%;height:1px;background:#e7e7e7;margin-bottom:-1px}@media print{#header{display:none !important}}#header-spacer{width:100%;visibility:hidden}@media print{#header-spacer{display:none}}#ipython_notebook{padding-left:0;padding-top:1px;padding-bottom:1px}@media (max-width:991px){#ipython_notebook{margin-left:10px}}#noscript{width:auto;padding-top:16px;padding-bottom:16px;text-align:center;font-size:22px;color:red;font-weight:bold}#ipython_notebook img{height:28px}#site{width:100%;display:none;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;overflow:auto}@med
|
|||
|
*
|
|||
|
* IPython auth
|
|||
|
*
|
|||
|
*/.center-nav{display:inline-block;margin-bottom:-4px}/*!
|
|||
|
*
|
|||
|
* IPython tree view
|
|||
|
*
|
|||
|
*/.alternate_upload{background-color:none;display:inline}.alternate_upload.form{padding:0;margin:0}.alternate_upload input.fileinput{display:inline;opacity:0;z-index:2;width:12ex;margin-right:-12ex}.alternate_upload .btn-upload{height:22px}ul#tabs{margin-bottom:4px}ul#tabs a{padding-top:6px;padding-bottom:4px}ul.breadcrumb a:focus,ul.breadcrumb a:hover{text-decoration:none}ul.breadcrumb i.icon-home{font-size:16px;margin-right:4px}ul.breadcrumb span{color:#5e5e5e}.list_toolbar{padding:4px 0 4px 0;vertical-align:middle}.list_toolbar .tree-buttons{padding-top:1px}.dynamic-buttons{padding-top:3px;display:inline-block}.list_toolbar [class*="span"]{min-height:24px}.list_header{font-weight:bold;background-color:#eee}.list_placeholder{font-weight:bold;padding-top:4px;padding-bottom:4px;padding-left:7px;padding-right:7px}.list_container{margin-top:4px;margin-bottom:20px;border:1px solid #ddd;border-radius:2px}.list_container>div{border-bottom:1px solid #ddd}.list_container>div:hover .list-item{background-color:red}.list_container>div:last-child{border:none}.list_item:hover .list_item{background-color:#ddd}.list_item a{text-decoration:none}.list_item:hover{background-color:#fafafa}.action_col{text-align:right}.list_header>div,.list_item>div{padding-top:4px;padding-bottom:4px;padding-left:7px;padding-right:7px;line-height:22px}.list_header>div input,.list_item>div input{margin-right:7px;margin-left:14px;vertical-align:baseline;line-height:22px;position:relative;top:-1px}.list_header>div .item_link,.list_item>div .item_link{margin-left:-1px;vertical-align:baseline;line-height:22px}.new-file input[type=checkbox]{visibility:hidden}.item_name{line-height:22px;height:24px}.item_icon{font-size:14px;color:#5e5e5e;margin-right:7px;margin-left:7px;line-height:22px;vertical-align:baseline}.item_buttons{line-height:1em;margin-left:-5px}.item_buttons .btn-group,.item_buttons .input-group{float:left}.item_buttons>.btn,.item_buttons>.btn-group,.item_buttons>.input-group{margin-left:5px}.item_buttons .btn{min-width:13ex}.item_buttons .running-indicator{padding-top:4px;color:#5cb85c}.toolbar_info{height:24px;line-height:24px}input.nbname_input,input.engine_num_input{padding-top:3px;padding-bottom:3px;height:22px;line-height:14px;margin:0}input.engine_num_input{width:60px}.highlight_text{color:blue}#project_name{display:inline-block;padding-left:7px;margin-left:-2px}#project_name>.breadcrumb{padding:0;margin-bottom:0;background-color:transparent;font-weight:bold}#tree-selector{padding-right:0}#button-select-all{min-width:50px}#select-all{margin-left:7px;margin-right:2px}.menu_icon{margin-right:2px}.tab-content .row{margin-left:0;margin-right:0}.folder_icon:before{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0);content:"\f114"}.folder_icon:before.pull-left{margin-right:.3em}.folder_icon:before.pull-right{margin-left:.3em}.notebook_icon:before{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0);content:"\f02d";position:relative;top:-1px}.notebook_icon:before.pull-left{margin-right:.3em}.notebook_icon:before.pull-right{margin-left:.3em}.running_notebook_icon:before{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0);content:"\f02d";position:relative;top:-1px;color:#5cb85c}.running_notebook_icon:before.pull-left{margin-right:.3em}.running_notebook_icon:before.pull-right{margin-left:.3em}.file_icon:before{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0);content:"\f016";position:relative;top:-2px}.file_icon:before.pull-left{margin-right:.3em}.file_icon:before.pull-right
|
|||
|
*
|
|||
|
* IPython text editor webapp
|
|||
|
*
|
|||
|
*/.selected-keymap i.fa{padding:0 5px}.selected-keymap i.fa:before{content:"\f00c"}#mode-menu{overflow:auto;max-height:20em}.edit_app #header{-webkit-box-shadow:0 0 12px 1px rgba(87,87,87,0.2);box-shadow:0 0 12px 1px rgba(87,87,87,0.2)}.edit_app #menubar .navbar{margin-bottom:-1px}.dirty-indicator{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0);width:20px}.dirty-indicator.pull-left{margin-right:.3em}.dirty-indicator.pull-right{margin-left:.3em}.dirty-indicator-dirty{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0);width:20px}.dirty-indicator-dirty.pull-left{margin-right:.3em}.dirty-indicator-dirty.pull-right{margin-left:.3em}.dirty-indicator-clean{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0);width:20px}.dirty-indicator-clean.pull-left{margin-right:.3em}.dirty-indicator-clean.pull-right{margin-left:.3em}.dirty-indicator-clean:before{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;transform:translate(0, 0);content:"\f00c"}.dirty-indicator-clean:before.pull-left{margin-right:.3em}.dirty-indicator-clean:before.pull-right{margin-left:.3em}#filename{font-size:16pt;display:table;padding:0 5px}#current-mode{padding-left:5px;padding-right:5px}#texteditor-backdrop{padding-top:20px;padding-bottom:20px}@media not print{#texteditor-backdrop{background-color:#eee}}@media print{#texteditor-backdrop #texteditor-container .CodeMirror-gutter,#texteditor-backdrop #texteditor-container .CodeMirror-gutters{background-color:#fff}}@media not print{#texteditor-backdrop #texteditor-container .CodeMirror-gutter,#texteditor-backdrop #texteditor-container .CodeMirror-gutters{background-color:#fff}}@media not print{#texteditor-backdrop #texteditor-container{padding:0;background-color:#fff;-webkit-box-shadow:0 0 12px 1px rgba(87,87,87,0.2);box-shadow:0 0 12px 1px rgba(87,87,87,0.2)}}/*!
|
|||
|
*
|
|||
|
* IPython notebook
|
|||
|
*
|
|||
|
*/.ansibold{font-weight:bold}.ansiblack{color:black}.ansired{color:darkred}.ansigreen{color:darkgreen}.ansiyellow{color:#c4a000}.ansiblue{color:darkblue}.ansipurple{color:darkviolet}.ansicyan{color:steelblue}.ansigray{color:gray}.ansibgblack{background-color:black}.ansibgred{background-color:red}.ansibggreen{background-color:green}.ansibgyellow{background-color:yellow}.ansibgblue{background-color:blue}.ansibgpurple{background-color:magenta}.ansibgcyan{background-color:cyan}.ansibggray{background-color:gray}div.cell{border:1px solid transparent;display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;display:flex;flex-direction:column;align-items:stretch;border-radius:2px;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;border-width:thin;border-style:solid;width:100%;padding:5px;margin:0;outline:none}div.cell.selected{border-color:#ababab}@media print{div.cell.selected{border-color:transparent}}.edit_mode div.cell.selected{border-color:green}@media print{.edit_mode div.cell.selected{border-color:transparent}}.prompt{min-width:14ex;padding:.4em;margin:0;font-family:monospace;text-align:right;line-height:1.21429em}@media (max-width:540px){.prompt{text-align:left}}div.inner_cell{display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;display:flex;flex-direction:column;align-items:stretch;-webkit-box-flex:1;-moz-box-flex:1;box-flex:1;flex:1}@-moz-document url-prefix(){div.inner_cell{overflow-x:hidden}}div.input_area{border:1px solid #cfcfcf;border-radius:2px;background:#f7f7f7;line-height:1.21429em}div.prompt:empty{padding-top:0;padding-bottom:0}div.unrecognized_cell{padding:5px 5px 5px 0;display:-webkit-box;-webkit-box-orient:horizontal;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:horizontal;-moz-box-align:stretch;display:box;box-orient:horizontal;box-align:stretch;display:flex;flex-direction:row;align-items:stretch}div.unrecognized_cell .inner_cell{border-radius:2px;padding:5px;font-weight:bold;color:red;border:1px solid #cfcfcf;background:#eaeaea}div.unrecognized_cell .inner_cell a{color:inherit;text-decoration:none}div.unrecognized_cell .inner_cell a:hover{color:inherit;text-decoration:none}@media (max-width:540px){div.unrecognized_cell>div.prompt{display:none}}@media print{div.code_cell{page-break-inside:avoid}}div.input{page-break-inside:avoid;display:-webkit-box;-webkit-box-orient:horizontal;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:horizontal;-moz-box-align:stretch;display:box;box-orient:horizontal;box-align:stretch;display:flex;flex-direction:row;align-items:stretch}@media (max-width:540px){div.input{display:-webkit-box;-webkit-box-orient:vertical;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:vertical;-moz-box-align:stretch;display:box;box-orient:vertical;box-align:stretch;display:flex;flex-direction:column;align-items:stretch}}div.input_prompt{color:navy;border-top:1px solid transparent}div.input_area>div.highlight{margin:.4em;border:none;padding:0;background-color:transparent}div.input_area>div.highlight>pre{margin:0;border:none;padding:0;background-color:transparent}.CodeMirror{line-height:1.21429em;font-size:14px;height:auto;background:none}.CodeMirror-scroll{overflow-y:hidden;overflow-x:auto}.CodeMirror-lines{padding:.4em}.CodeMirror-linenumber{padding:0 8px 0 4px}.CodeMirror-gutters{border-bottom-left-radius:2px;border-top-left-radius:2px}.CodeMirror pre{padding:0;border:0;border-radius:0}.highlight-base{color:#000}.highlight-variable{color:#000}.highlight-variable-2{color:#1a1a1a}.highlight-variable-3{color:#333}.highlight-string{color:#ba2121}.highlight-comment{color:#408080;font-style:italic}.highlight-number{color:#080}.highlight-atom{color:#88f}.highlight-keyword{color:#008000;font-weight:bold}.highlight-builtin{color:#008000}.highlight-error{color:#f00}.highlight-operator
|
|||
|
*
|
|||
|
* IPython notebook webapp
|
|||
|
*
|
|||
|
*/@media (max-width:767px){.notebook_app{padding-left:0;padding-right:0}}#ipython-main-app{box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;height:100%}div#notebook_panel{margin:0;padding:0;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;height:100%}#notebook{font-size:14px;line-height:20px;overflow-y:hidden;overflow-x:auto;width:100%;padding-top:20px;margin:0;outline:none;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;min-height:100%}@media not print{#notebook-container{padding:15px;background-color:#fff;min-height:0;-webkit-box-shadow:0 0 12px 1px rgba(87,87,87,0.2);box-shadow:0 0 12px 1px rgba(87,87,87,0.2)}}div.ui-widget-content{border:1px solid #ababab;outline:none}pre.dialog{background-color:#f7f7f7;border:1px solid #ddd;border-radius:2px;padding:.4em;padding-left:2em}p.dialog{padding:.2em}pre,code,kbd,samp{white-space:pre-wrap}#fonttest{font-family:monospace}p{margin-bottom:0}.end_space{min-height:100px;transition:height .2s ease}.notebook_app #header{-webkit-box-shadow:0 0 12px 1px rgba(87,87,87,0.2);box-shadow:0 0 12px 1px rgba(87,87,87,0.2)}@media not print{.notebook_app{background-color:#eee}}.celltoolbar{border:thin solid #cfcfcf;border-bottom:none;background:#eee;border-radius:2px 2px 0 0;width:100%;height:29px;padding-right:4px;display:-webkit-box;-webkit-box-orient:horizontal;-webkit-box-align:stretch;display:-moz-box;-moz-box-orient:horizontal;-moz-box-align:stretch;display:box;box-orient:horizontal;box-align:stretch;display:flex;flex-direction:row;align-items:stretch;-webkit-box-pack:end;-moz-box-pack:end;box-pack:end;justify-content:flex-end}@media print{.celltoolbar{display:none}}.ctb_hideshow{display:none;vertical-align:bottom}.ctb_global_show .ctb_show.ctb_hideshow{display:block}.ctb_global_show .ctb_show+.input_area,.ctb_global_show .ctb_show+div.text_cell_input,.ctb_global_show .ctb_show~div.text_cell_render{border-top-right-radius:0;border-top-left-radius:0}.ctb_global_show .ctb_show~div.text_cell_render{border:1px solid #cfcfcf}.celltoolbar{font-size:87%;padding-top:3px}.celltoolbar select{display:block;width:100%;height:32px;padding:6px 12px;font-size:13px;line-height:1.42857143;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:2px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s;height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:1px;width:inherit;font-size:inherit;height:22px;padding:0;display:inline-block}.celltoolbar select:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6)}.celltoolbar select::-moz-placeholder{color:#999;opacity:1}.celltoolbar select:-ms-input-placeholder{color:#999}.celltoolbar select::-webkit-input-placeholder{color:#999}.celltoolbar select[disabled],.celltoolbar select[readonly],fieldset[disabled] .celltoolbar select{cursor:not-allowed;background-color:#eee;opacity:1}textarea.celltoolbar select{height:auto}select.celltoolbar select{height:30px;line-height:30px}textarea.celltoolbar select,select[multiple].celltoolbar select{height:auto}.celltoolbar label{margin-left:5px;margin-right:5px}.completions{position:absolute;z-index:10;overflow:hidden;border:1px solid #ababab;border-radius:2px;-webkit-box-shadow:0 6px 10px -1px #adadad;box-shadow:0 6px 10px -1px #adadad}.completions select{background:white;outline:none;border:none;padding:0;margin:0;overflow:auto;font-family:monospace;font-size:110%;color:#000;width:auto}.completions select option.context{color:#286090}#kernel_logo_widget{float:right !important;float:right}#kernel_logo_widget .current_kernel_logo{display:none;margin-top:-1px;margin-bottom:-1px;wid
|
|||
|
</style>
|
|||
|
<style type="text/css">
|
|||
|
.highlight .hll { background-color: #ffffcc }
|
|||
|
.highlight { background: #f8f8f8; }
|
|||
|
.highlight .c { color: #408080; font-style: italic } /* Comment */
|
|||
|
.highlight .err { border: 1px solid #FF0000 } /* Error */
|
|||
|
.highlight .k { color: #008000; font-weight: bold } /* Keyword */
|
|||
|
.highlight .o { color: #666666 } /* Operator */
|
|||
|
.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
|
|||
|
.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
|
|||
|
.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
|
|||
|
.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
|
|||
|
.highlight .gd { color: #A00000 } /* Generic.Deleted */
|
|||
|
.highlight .ge { font-style: italic } /* Generic.Emph */
|
|||
|
.highlight .gr { color: #FF0000 } /* Generic.Error */
|
|||
|
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
|||
|
.highlight .gi { color: #00A000 } /* Generic.Inserted */
|
|||
|
.highlight .go { color: #888888 } /* Generic.Output */
|
|||
|
.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
|
|||
|
.highlight .gs { font-weight: bold } /* Generic.Strong */
|
|||
|
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
|||
|
.highlight .gt { color: #0044DD } /* Generic.Traceback */
|
|||
|
.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
|
|||
|
.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
|
|||
|
.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
|
|||
|
.highlight .kp { color: #008000 } /* Keyword.Pseudo */
|
|||
|
.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
|
|||
|
.highlight .kt { color: #B00040 } /* Keyword.Type */
|
|||
|
.highlight .m { color: #666666 } /* Literal.Number */
|
|||
|
.highlight .s { color: #BA2121 } /* Literal.String */
|
|||
|
.highlight .na { color: #7D9029 } /* Name.Attribute */
|
|||
|
.highlight .nb { color: #008000 } /* Name.Builtin */
|
|||
|
.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
|
|||
|
.highlight .no { color: #880000 } /* Name.Constant */
|
|||
|
.highlight .nd { color: #AA22FF } /* Name.Decorator */
|
|||
|
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
|
|||
|
.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
|
|||
|
.highlight .nf { color: #0000FF } /* Name.Function */
|
|||
|
.highlight .nl { color: #A0A000 } /* Name.Label */
|
|||
|
.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
|
|||
|
.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
|
|||
|
.highlight .nv { color: #19177C } /* Name.Variable */
|
|||
|
.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
|
|||
|
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
|
|||
|
.highlight .mb { color: #666666 } /* Literal.Number.Bin */
|
|||
|
.highlight .mf { color: #666666 } /* Literal.Number.Float */
|
|||
|
.highlight .mh { color: #666666 } /* Literal.Number.Hex */
|
|||
|
.highlight .mi { color: #666666 } /* Literal.Number.Integer */
|
|||
|
.highlight .mo { color: #666666 } /* Literal.Number.Oct */
|
|||
|
.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
|
|||
|
.highlight .sc { color: #BA2121 } /* Literal.String.Char */
|
|||
|
.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
|
|||
|
.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
|
|||
|
.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
|
|||
|
.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
|
|||
|
.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
|
|||
|
.highlight .sx { color: #008000 } /* Literal.String.Other */
|
|||
|
.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
|
|||
|
.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
|
|||
|
.highlight .ss { color: #19177C } /* Literal.String.Symbol */
|
|||
|
.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
|
|||
|
.highlight .vc { color: #19177C } /* Name.Variable.Class */
|
|||
|
.highlight .vg { color: #19177C } /* Name.Variable.Global */
|
|||
|
.highlight .vi { color: #19177C } /* Name.Variable.Instance */
|
|||
|
.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
|
|||
|
</style>
|
|||
|
|
|||
|
|
|||
|
<style type="text/css">
|
|||
|
/* Overrides of notebook CSS for static HTML export */
|
|||
|
body {
|
|||
|
overflow: visible;
|
|||
|
padding: 8px;
|
|||
|
}
|
|||
|
|
|||
|
div#notebook {
|
|||
|
overflow: visible;
|
|||
|
border-top: none;
|
|||
|
}
|
|||
|
|
|||
|
@media print {
|
|||
|
div.cell {
|
|||
|
display: block;
|
|||
|
page-break-inside: avoid;
|
|||
|
}
|
|||
|
div.output_wrapper {
|
|||
|
display: block;
|
|||
|
page-break-inside: avoid;
|
|||
|
}
|
|||
|
div.output {
|
|||
|
display: block;
|
|||
|
page-break-inside: avoid;
|
|||
|
}
|
|||
|
}
|
|||
|
</style>
|
|||
|
|
|||
|
<!-- Custom stylesheet, it must be in the same directory as the html file -->
|
|||
|
<link rel="stylesheet" href="custom.css">
|
|||
|
|
|||
|
<!-- Loading mathjax macro -->
|
|||
|
<!-- Load mathjax -->
|
|||
|
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
|
|||
|
<!-- MathJax configuration -->
|
|||
|
<script type="text/x-mathjax-config">
|
|||
|
MathJax.Hub.Config({
|
|||
|
tex2jax: {
|
|||
|
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
|
|||
|
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
|
|||
|
processEscapes: true,
|
|||
|
processEnvironments: true
|
|||
|
},
|
|||
|
// Center justify equations in code and markdown cells. Elsewhere
|
|||
|
// we use CSS to left justify single line equations in code cells.
|
|||
|
displayAlign: 'center',
|
|||
|
"HTML-CSS": {
|
|||
|
styles: {'.MathJax_Display': {"margin": 0}},
|
|||
|
linebreaks: { automatic: true }
|
|||
|
}
|
|||
|
});
|
|||
|
</script>
|
|||
|
<!-- End of mathjax configuration -->
|
|||
|
|
|||
|
</head>
|
|||
|
<body>
|
|||
|
<div tabindex="-1" id="notebook" class="border-box-sizing">
|
|||
|
<div class="container" id="notebook-container">
|
|||
|
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h1 id="Projets-Python">Projets Python<a class="anchor-link" href="#Projets-Python">¶</a></h1><p>Dans ce cours autour de la programmation Python et de l'algorithmie, nous verons beaucoup de petits morceaux de programmes.</p>
|
|||
|
<p>Il est vivement recommander de ne pas faire <strong>que</strong> les questions poser mais aussi d'<strong>expérimenter</strong> par soi même.</p>
|
|||
|
<ul>
|
|||
|
<li><a href="#Introduction-Python">Introduction à Python</a></li>
|
|||
|
<li><a href="#Générateur-d'excuses">Générateur d'excuses</a></li>
|
|||
|
<li><a href="#Magic-8-ball">Magic 8 ball</a></li>
|
|||
|
<li><a href="#Deviner-un-nombre">Deviner un nombre</a></li>
|
|||
|
<li><a href="#Pierre-Feuille-Ciseau">Pierre feuille ciseau</a></li>
|
|||
|
<li><a href="#Deviner-un-nombre">Deviner un nombre (améliorations)</a></li>
|
|||
|
<li><a href="#Generateur-de-simleys">Generateur de Smiley</a></li>
|
|||
|
<li><a href="#Chiffrement-de-Cesar">Chiffrement de Cesar</a></li>
|
|||
|
<li><a href="#Polynome-du-2nd-degre">Polynome du 2nd degré</a></li>
|
|||
|
</ul>
|
|||
|
<hr>
|
|||
|
<p>Notions de programmation</p>
|
|||
|
<ul>
|
|||
|
<li><a href="#input">input</a></li>
|
|||
|
<li><a href="#Condition-if">Les conditions if</a></li>
|
|||
|
<li><a href="#Boucles-for">Les boucles for</a></li>
|
|||
|
<li><a href="#Boucles-while">Les boucles while</a></li>
|
|||
|
<li><a href="#Fonction">Les fonctions</a></li>
|
|||
|
</ul>
|
|||
|
<hr>
|
|||
|
<p>Ressouces Python</p>
|
|||
|
<ul>
|
|||
|
<li><a href="http://openclassrooms.com/courses/apprenez-a-programmer-en-python">site du zero</a> (cours en ligne)</li>
|
|||
|
<li><a href="http://www.codecademy.com/">codeacademy</a> (cours en ligne)</li>
|
|||
|
<li><a href="http://codecombat.com">code conbat</a> (jeu en ligne qui se joue en codant)</li>
|
|||
|
<li><a href="http://www.checkio.org/">checkio</a> (jeu en ligne - anglais - avec beaucoup de langage différents)</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Introduction-Python">Introduction Python<a class="anchor-link" href="#Introduction-Python">¶</a></h2><p>Dans les encadrés, on peut lancer des commandes Python et écrire des petits programmes.</p>
|
|||
|
<p>La touche <strong>F5</strong> ou l'icône en triangle vert permet d'executer tout le programme écrit dans la partie de droite.</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [59]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="k">print</span> <span class="s">"Bonjour"</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>Bonjour
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li>Modifier la commande précédente pour qu'elle n'affiche plus bonjour mais votre nom puis executer cette commande.</li>
|
|||
|
</ul>
|
|||
|
<p>Il est possible d'afficher plusieurs messages:</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [2]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="k">print</span> <span class="s">"bonjour"</span>
|
|||
|
<span class="k">print</span> <span class="s">'monde'</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>bonjour
|
|||
|
monde
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li><p>Modifier le programme précédent pour qu'il affiche:</p>
|
|||
|
<p>Bonjour</p>
|
|||
|
<p>tous</p>
|
|||
|
<p>le</p>
|
|||
|
<p>monde</p>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
<p>Quand une ligne commence par un #, Python ne la lit pas. On appelle cela des commentaires. Nous les utiliserons pour expliquer ce que l'on fait.</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [3]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="c"># la commande suivante affiche Bonjour</span>
|
|||
|
<span class="k">print</span><span class="p">(</span><span class="s">'bonjour'</span><span class="p">)</span>
|
|||
|
<span class="c"># Quand on veut afficher quelque chose, on utilisera la commande print()</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>bonjour
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Les-variables">Les variables<a class="anchor-link" href="#Les-variables">¶</a></h2><p>Les variables sont des <em>enveloppes</em> où l'on stockera des nombres, des mots, des phrases ou des choses plus compliqués.</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [4]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">un_nombre</span> <span class="o">=</span> <span class="mi">10</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Ainsi dans <em>l'enveloppe</em> appelée <strong>un_nombre</strong> on y met le nombre 10.</p>
|
|||
|
<p>C'est ce que l'on appelle <strong>assigner</strong> une <strong>valeur</strong> à une variable ou <strong>stocker</strong> une valeur dans une variable.</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [5]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">un_nombre</span> <span class="o">=</span> <span class="mi">10</span>
|
|||
|
<span class="k">print</span> <span class="n">un_nombre</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>10
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li>Modifier le programme précédent pour stocker 2 dans <strong>un_nombre</strong> puis l'afficher.</li>
|
|||
|
</ul>
|
|||
|
<p>Pour stocker des mots ou des phrases, il faut les mettre entre guillemets</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [6]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">un_mot</span> <span class="o">=</span> <span class="s">"Coucou"</span>
|
|||
|
<span class="n">une_phrase</span> <span class="o">=</span> <span class="s">"ceci est une phrase"</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li>Modifier le programme précédent pour changer le contenu des variables puis ajouter deux lignes pour afficher ce que contiennent ces variables (avec la commande <code>print</code>).</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Générateur-d'excuses">Générateur d'excuses<a class="anchor-link" href="#Générateur-d'excuses">¶</a></h2><p>Quand Loïc fait des bétises, il se fait souvent prendre et doit trouver une excuse le plus rapidement possible. Aidons le en créant un programme qui créé des excuses sur commande.</p>
|
|||
|
<p>Ces excuses auront le modèle suivant</p>
|
|||
|
|
|||
|
<pre><code>C'est pas moi! C'est (Bob).
|
|||
|
Il a (mangé) une (grenouille) (volante). Alors que moi j'étais tranquillement en train de (faire) un (super) (exercice de math).
|
|||
|
Je suis innocent (monsieur)!
|
|||
|
|
|||
|
</code></pre>
|
|||
|
<p>Les nombres entre parenthèses seront remplacé par des mots choisis par l'utilisateur de ce générateur.</p>
|
|||
|
<p>Pour écrire du texte avec une variable, il faut séparer les parties par une virgule:</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [7]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">age</span> <span class="o">=</span> <span class="mi">14</span>
|
|||
|
<span class="k">print</span> <span class="s">"J'ai "</span><span class="p">,</span> <span class="n">age</span><span class="p">,</span> <span class="s">"ans"</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>J'ai 14 ans
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li>Modifier les lignes précédentes pour se présenter <strong>Bonjour, je m'appelle (Bob)</strong>.</li>
|
|||
|
</ul>
|
|||
|
<p>Pour demander quelque chose à l'utilisateur, on utilise la fonction <code>input</code></p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [13]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">coupable</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">"Nom du coupable (masculin)? "</span><span class="p">)</span>
|
|||
|
<span class="k">print</span> <span class="s">"C'est pas moi! C'est "</span><span class="p">,</span> <span class="n">coupable</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>Nom du coupable (masculin)? "Marc"
|
|||
|
C'est pas moi! C'est Marc
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li>Finir d'écrire le programme qui permettra de générer une excuse</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Magic-8-ball">Magic 8 ball<a class="anchor-link" href="#Magic-8-ball">¶</a></h2><p>Pour ceux qui ne connaissent pas un Magic 8 ball est un boule magique qui répond à toutes les questions (<a href="https://www.youtube.com/watch?v=9gaQwIrBNPw">vidéo</a>).</p>
|
|||
|
<p>Même si je ne voudrai pas gacher votre âme d'enfant, cette boule magique répond au hasard... Pour gérer le hasard en Python, on utilise <strong>random</strong>. Il faut donc placer la ligne suivante au début du fichier à chaque fois que l'on veut faire quelque chose au hasard.</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [14]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="kn">import</span> <span class="nn">random</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Nous allons mettre toutes les réponses possibles dans une liste</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [15]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">reponses</span> <span class="o">=</span> <span class="p">[</span><span class="s">"reponse 1"</span><span class="p">,</span> <span class="s">"reponse 2"</span><span class="p">,</span> <span class="s">"reponse 3"</span><span class="p">]</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Et Python choisira une réponse au hasard</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [16]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">reponses</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt output_prompt">Out[16]:</div>
|
|||
|
|
|||
|
|
|||
|
<div class="output_text output_subarea output_execute_result">
|
|||
|
<pre>'reponse 3'</pre>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li>En réutilisant la fonction <strong>input</strong> vue précédement, écrire un programme qui propose de poser une question et qui lui apporte une réponse!</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Deviner-un-nombre">Deviner un nombre<a class="anchor-link" href="#Deviner-un-nombre">¶</a></h2><p>Nous allons maintenant écrire un programme qui va chercher à faire deviner à l'utilisateur un nombre choisi aléatoirement par Python.</p>
|
|||
|
<p>Pour faire choisir un nombre entier à Python, on utilise la fonction <code>randint(min,max)</code> (<code>randint</code> signifie random integer = entier aléatoire)</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [17]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">nbr_aleatoire</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">20</span><span class="p">)</span>
|
|||
|
<span class="k">print</span> <span class="n">nbr_aleatoire</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>5
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Faites executer plusieurs fois cette commande pour remarquer qu'elle ne retourne pas toujours le même résultat.</p>
|
|||
|
<ul>
|
|||
|
<li><p>Completer votre programme pour demander une réponse à l'utilisateur <em>(utilisez <code>int(input("question"))</code> plutôt que <code>input("question")</code> pour que la réponse soit transformée en entier)</em></p>
|
|||
|
</li>
|
|||
|
<li><p>Regarder la section sur <a href="#Condition-if">Condition if</a> pour adapter l'exemple et savoir lequel du nombre choisi par l'ordinateur ou de l'utilisateur est le plus grand.</p>
|
|||
|
</li>
|
|||
|
<li><p>Écrire le programme final qui fait choisir un nombre à l'ordinateur, qui demande un nombre à l'utilisateur puis qui dit si le nombre donné par l'utilisateur est plus grand ou plus petit.</p>
|
|||
|
</li>
|
|||
|
<li><p>Pour améliorer notre programme, il faudrait que l'utilisateur puisse rententer de deviner le nombre. Regardez la section <a href="#Boucle-while">Boucle while</a> pour améliorer votre programme.</p>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Pierre-Feuille-Ciseau">Pierre Feuille Ciseau<a class="anchor-link" href="#Pierre-Feuille-Ciseau">¶</a></h2><p>Vous devez connaître le jeu Pierre-Feuille-Ciseau. Deux adversaires s'affrontent choissicent en même temps Pierre, Feuille ou Ciseau.</p>
|
|||
|
<p>Pierre gagne contre ciseau qui gagne contre feuille qui gagne contre pierre...</p>
|
|||
|
<p>Nous allons écrire un jeu qui fera s'affronter l'utilisateur contre l'ordinateur.</p>
|
|||
|
<h3 id="Choix-du-joueur-et-choix-de-l'ordinateur">Choix du joueur et choix de l'ordinateur<a class="anchor-link" href="#Choix-du-joueur-et-choix-de-l'ordinateur">¶</a></h3><ul>
|
|||
|
<li>Écrire un programme qui demande le choix de l'utilisateur</li>
|
|||
|
<li>Completer ce programme pour que l'ordinateur choisisse parmi les 3 choix</li>
|
|||
|
</ul>
|
|||
|
<h3 id="Comparaison-des-résultats">Comparaison des résultats<a class="anchor-link" href="#Comparaison-des-résultats">¶</a></h3><ul>
|
|||
|
<li>En utilisant les <a href="#Condition-if">conditions if</a> comparer les deux choix pour determiner qui est le vaincueur.</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Deviner-un-nombre-(amélioration)">Deviner un nombre (amélioration)<a class="anchor-link" href="#Deviner-un-nombre-(amélioration)">¶</a></h2><p>Reprenez votre programme qui fait deviner à l'utilisateur un nombre choisi par l'ordinateur. Le soucis de ce programme est que nous n'avons qu'un essai ce qui n'est pas très pratique pour trouver le nombre...</p>
|
|||
|
<p>Nous allons améliorer ce programme laisser plus de chance à l'utilisateur. Pour cela nous allons faire une boucle <code>while</code> (tant que en français).</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [19]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">a</span> <span class="o">=</span> <span class="mi">11</span>
|
|||
|
<span class="k">while</span> <span class="n">a</span> <span class="o"><</span> <span class="mi">20</span><span class="p">:</span> <span class="c">#tant que a est plus petit que 20</span>
|
|||
|
<span class="k">print</span> <span class="s">"un tour"</span>
|
|||
|
<span class="n">a</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="mi">1</span>
|
|||
|
<span class="k">print</span> <span class="s">"Fini! Et a vaut "</span><span class="p">,</span> <span class="n">a</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>un tour
|
|||
|
un tour
|
|||
|
un tour
|
|||
|
un tour
|
|||
|
un tour
|
|||
|
un tour
|
|||
|
un tour
|
|||
|
un tour
|
|||
|
un tour
|
|||
|
Fini! Et a vaut 20
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>On peut aussi créer une variable <code>aPasTrouve = True</code> (True en anglais signifie vrai) et dès que l'utilisateur a trouvé la bonne valeur, on change <code>aPasTrouve = False</code> (False en anglais signifie faux).</p>
|
|||
|
<ul>
|
|||
|
<li>Écrire cette amélioration du programme.</li>
|
|||
|
<li>Améliorer votre programme, en comptant le nombre de tentatives.</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Generateur-de-simleys">Generateur de simleys<a class="anchor-link" href="#Generateur-de-simleys">¶</a></h2><p>Pour ce projet, nous allons programmer un générateur de smileys. Nous allons définir quelquels éléments de ce smiley et l'ordinateur choisira aléatoirement parmi ces éléments pour créer le smiley.</p>
|
|||
|
<p>Voici les éléments du smiley.</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [58]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">LISTE_CHAPEAU</span> <span class="o">=</span> <span class="p">[</span><span class="s">u" </span><span class="se">\n</span><span class="s"> _===_"</span><span class="p">,</span> <span class="s">" ___ </span><span class="se">\n</span><span class="s"> ....."</span><span class="p">,</span> <span class="s">" _ </span><span class="se">\n</span><span class="s"> /_\ "</span><span class="p">,</span> <span class="s">" ___ </span><span class="se">\n</span><span class="s"> (_*_)"</span><span class="p">]</span>
|
|||
|
<span class="n">LISTE_NEZ</span> <span class="o">=</span> <span class="p">[</span><span class="s">u","</span><span class="p">,</span> <span class="s">"."</span><span class="p">,</span> <span class="s">"_"</span><span class="p">,</span> <span class="s">" "</span><span class="p">]</span>
|
|||
|
<span class="n">LISTE_OEIL</span> <span class="o">=</span> <span class="p">[</span><span class="s">u"."</span><span class="p">,</span> <span class="s">"o"</span><span class="p">,</span> <span class="s">"O"</span><span class="p">,</span> <span class="s">"-"</span><span class="p">]</span>
|
|||
|
<span class="n">LISTE_GAUCHE_CORPS_HAUT</span> <span class="o">=</span> <span class="p">[</span><span class="s">u" "</span><span class="p">,</span> <span class="s">"</span><span class="se">\\</span><span class="s">"</span><span class="p">,</span> <span class="s">" "</span><span class="p">,</span> <span class="s">" "</span><span class="p">]</span>
|
|||
|
<span class="n">LISTE_GAUCHE_CORPS_BAS</span> <span class="o">=</span> <span class="p">[</span><span class="s">u"<"</span><span class="p">,</span> <span class="s">" "</span><span class="p">,</span> <span class="s">"/"</span><span class="p">,</span> <span class="s">" "</span><span class="p">]</span>
|
|||
|
<span class="n">LISTE_DROITE_CORPS_HAUT</span> <span class="o">=</span> <span class="p">[</span><span class="s">u" "</span><span class="p">,</span> <span class="s">"/"</span><span class="p">,</span> <span class="s">" "</span><span class="p">,</span> <span class="s">" "</span><span class="p">]</span>
|
|||
|
<span class="n">LISTE_DROITE_CORPS_BAS</span> <span class="o">=</span> <span class="p">[</span><span class="s">u">"</span><span class="p">,</span> <span class="s">" "</span><span class="p">,</span> <span class="s">"</span><span class="se">\\</span><span class="s">"</span><span class="p">,</span> <span class="s">" "</span><span class="p">]</span>
|
|||
|
<span class="n">LISTE_TORSE</span> <span class="o">=</span> <span class="p">[</span><span class="s">u" : "</span><span class="p">,</span> <span class="s">"] ["</span><span class="p">,</span> <span class="s">"> <"</span><span class="p">,</span> <span class="s">" "</span><span class="p">]</span>
|
|||
|
<span class="n">LISTE_BASE</span> <span class="o">=</span> <span class="p">[</span><span class="s">u" : "</span><span class="p">,</span> <span class="s">'" "'</span><span class="p">,</span> <span class="s">"___"</span><span class="p">,</span> <span class="s">" "</span><span class="p">]</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li><p>Le programme qui séléctionnera aléatoirement des éléments pour construire un smiley de ce type:</p>
|
|||
|
|
|||
|
<pre><code> _
|
|||
|
/_\
|
|||
|
(o O)
|
|||
|
<( : )
|
|||
|
(" ") </code></pre>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Polynome-du-2nd-degre">Polynome du 2nd degre<a class="anchor-link" href="#Polynome-du-2nd-degre">¶</a></h2><p>On veut écrire un programme qui manipule les polynomes du 2nd degré qui l'on améliorera petit à petit.</p>
|
|||
|
<ul>
|
|||
|
<li><p>Écrire un programme qui demande les valeurs de <code>a</code>, <code>b</code> et <code>c</code> (les coefficients du polynome) et renvoie les racines du polynôme $ax^2 + bx + c$</p>
|
|||
|
|
|||
|
<pre><code> Valeur de a?
|
|||
|
4
|
|||
|
Valeur de b?
|
|||
|
4
|
|||
|
Valeur de c?
|
|||
|
1
|
|||
|
Delta = 0, il y a une racine:
|
|||
|
x = 0.5</code></pre>
|
|||
|
</li>
|
|||
|
<li><p>On veut maintenant améliorer notre programme pour qu'il donne le tableau de signe du polynôme.</p>
|
|||
|
|
|||
|
<pre><code> Valeur de a?
|
|||
|
4
|
|||
|
Valeur de b?
|
|||
|
4
|
|||
|
Valeur de c?
|
|||
|
1
|
|||
|
Delta = 0, il y a une racine:
|
|||
|
x = 0.5
|
|||
|
Comme a = 4 donc le tableau de signe est
|
|||
|
|
|||
|
-------------------------
|
|||
|
x | -inf 0.5 +inf
|
|||
|
-----------------------------
|
|||
|
P | + 0 +
|
|||
|
-----------------------------</code></pre>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Chiffrement-de-Cesar">Chiffrement de Cesar<a class="anchor-link" href="#Chiffrement-de-Cesar">¶</a></h2><p>Le chiffrement de César, utilisé par Jules César pour transmettre des messages secrets dans l’Antiquité, consiste décaler les lettres dans l'alphabet pour écrire un message.</p>
|
|||
|
<p>Voici un exemple avec un décalage de 4</p>
|
|||
|
|
|||
|
<pre><code> message >>> bonjour
|
|||
|
chiffré >>> fsrnsyv
|
|||
|
|
|||
|
</code></pre>
|
|||
|
<p>Le <code>b</code> devient <code>f</code>, <code>o</code> devient <code>s</code> etc...</p>
|
|||
|
<ul>
|
|||
|
<li>Avec un crayon et du papier chiffrer <code>bonjour</code> avec un décalage de 6.</li>
|
|||
|
</ul>
|
|||
|
<p>Python est plus fort pour manipuler les nombres que les lettres. Il faudra donc commencer par transformer les lettres en nombre (on appelle cela <strong>encoder</strong>). Il existe une fonction faite pour ça: <code>ord</code></p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [43]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">codage_a</span> <span class="o">=</span> <span class="nb">ord</span><span class="p">(</span><span class="s">"a"</span><span class="p">)</span>
|
|||
|
<span class="k">print</span> <span class="n">codage_a</span>
|
|||
|
<span class="n">codage_b</span> <span class="o">=</span> <span class="nb">ord</span><span class="p">(</span><span class="s">"b"</span><span class="p">)</span>
|
|||
|
<span class="k">print</span> <span class="n">codage_b</span>
|
|||
|
<span class="n">codage_A</span> <span class="o">=</span> <span class="nb">ord</span><span class="p">(</span><span class="s">"A"</span><span class="p">)</span>
|
|||
|
<span class="k">print</span> <span class="n">codage_A</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>97
|
|||
|
98
|
|||
|
65
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Pour faire la transformation inverse, on utilisera la fonction <code>chr</code></p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [46]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">lettre_100</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
|
|||
|
<span class="k">print</span> <span class="n">lettre_100</span>
|
|||
|
<span class="n">lettre_43</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">43</span><span class="p">)</span>
|
|||
|
<span class="k">print</span> <span class="n">lettre_43</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>d
|
|||
|
+
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Vous retrouverez tous les caractères et leurs nombres <a href="http://www.asciitable.com/">ici</a>. On peut remarquer qu'il y en a 256 (souvenez en vous on s'en servira plus tard)</p>
|
|||
|
<p>Il faut donc transformer le message en liste de nombre. Pour cela on utilisera des <a href="#Boucle-for">Boucles for</a>:</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [47]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">message</span> <span class="o">=</span> <span class="s">"Bonjour"</span>
|
|||
|
<span class="n">message_code</span> <span class="o">=</span> <span class="p">[]</span> <span class="c">#le message codé est pour le moment une liste vide</span>
|
|||
|
<span class="k">for</span> <span class="n">lettre</span> <span class="ow">in</span> <span class="n">message</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="s">"la lettre "</span><span class="p">,</span> <span class="n">lettre</span><span class="p">,</span> <span class="s">"est transformée en le nombre"</span><span class="p">,</span> <span class="nb">ord</span><span class="p">(</span><span class="n">lettre</span><span class="p">)</span>
|
|||
|
<span class="n">message_code</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="n">lettre</span><span class="p">))</span> <span class="c">#append signifie ajouter en anglais</span>
|
|||
|
|
|||
|
<span class="k">print</span> <span class="n">message_code</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>la lettre B est transformée en le nombre 66
|
|||
|
la lettre o est transformée en le nombre 111
|
|||
|
la lettre n est transformée en le nombre 110
|
|||
|
la lettre j est transformée en le nombre 106
|
|||
|
la lettre o est transformée en le nombre 111
|
|||
|
la lettre u est transformée en le nombre 117
|
|||
|
la lettre r est transformée en le nombre 114
|
|||
|
[66, 111, 110, 106, 111, 117, 114]
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Il faut maintenant décaler tous ces nombres</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [48]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">message_decale</span> <span class="o">=</span> <span class="p">[]</span>
|
|||
|
<span class="n">decalage</span> <span class="o">=</span> <span class="mi">6</span>
|
|||
|
<span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">message_code</span><span class="p">:</span>
|
|||
|
<span class="n">message_decale</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">n</span> <span class="o">+</span> <span class="n">decalage</span><span class="p">)</span><span class="o">%</span><span class="k">256</span>)
|
|||
|
<span class="k">print</span> <span class="n">message_decale</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>[72, 117, 116, 112, 117, 123, 120]
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Le <code>%256</code> est là pour être sûr qu'aucun nombre ne dépasse 255. Si un nombre dépasse 255, on recommence par 0 (par exemple 259 devient 3 c'est le reste de la division euclidienne de 259 par 256)</p>
|
|||
|
<p>Il faut maintenant décodé le <code>message_decale</code> pour avoir à nouveau des lettres</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [49]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">message_chiffre</span> <span class="o">=</span> <span class="p">[]</span>
|
|||
|
<span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">message_decale</span><span class="p">:</span>
|
|||
|
<span class="n">message_chiffre</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">chr</span><span class="p">(</span><span class="n">n</span><span class="p">))</span>
|
|||
|
<span class="k">print</span> <span class="n">message_chiffre</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>['H', 'u', 't', 'p', 'u', '{', 'x']
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Ensuite on lie toutes les lettres pour en faire un seul mot</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [51]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">message_chiffre</span> <span class="o">=</span> <span class="s">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">message_chiffre</span><span class="p">)</span> <span class="c"># join en anglais signifie joindre</span>
|
|||
|
<span class="k">print</span> <span class="n">message_chiffre</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>Hutpu{x
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Voila votre programme sais chiffrer des messages.</p>
|
|||
|
<ul>
|
|||
|
<li>Écrire un programme qui sais déchiffrer les messages.</li>
|
|||
|
<li>Pour améliorer votre programme, on peut utiliser des <a href="#fonction">fonctions</a>.</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<hr>
|
|||
|
<h2 id="input">input<a class="anchor-link" href="#input">¶</a></h2><p>Contrairement à ce que l'on a fait hier on ne met plus rien dans les parenthèses d'un <code>input</code>.</p>
|
|||
|
<p><code>input()</code> est une commande qui va demander à l'utilisateur une information</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [34]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="k">print</span> <span class="s">"Comment t'appelles tu?"</span>
|
|||
|
<span class="n">nom</span> <span class="o">=</span> <span class="nb">input</span><span class="p">()</span>
|
|||
|
<span class="k">print</span> <span class="s">"Ah! Tu t'appelles"</span><span class="p">,</span> <span class="n">nom</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>Comment t'appelles tu?
|
|||
|
"plop"
|
|||
|
Ah! Tu t'appelles plop
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Après avoir afficher la question, l'ordinateur se met en pose et attend que l'utilisateur réponde quelque chose. Une fois que l'utilisateur a répondu (a appuyé sur <code>entrer</code>) la réponse est stocké, ici, dans la variable <code>nom</code>.</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Condition-if">Condition if<a class="anchor-link" href="#Condition-if">¶</a></h2><p>Pour différencier plusieurs cas, on utilisera la commande <code>if</code> (si), <code>elif</code> (sinon si) et <code>else</code> (sinon).</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [35]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">a</span> <span class="o">=</span> <span class="mi">2</span>
|
|||
|
<span class="n">b</span> <span class="o">=</span> <span class="mi">3</span>
|
|||
|
|
|||
|
<span class="k">if</span> <span class="n">a</span> <span class="o">></span> <span class="n">b</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="s">"a plus grand que b"</span>
|
|||
|
<span class="k">elif</span> <span class="n">a</span> <span class="o">==</span> <span class="n">b</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="s">"a est égal à b"</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="s">"a est plus petit que b"</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>a est plus petit que b
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Boucles-for">Boucles for<a class="anchor-link" href="#Boucles-for">¶</a></h2><p>Les boucles <strong>for</strong> permettent de répéter un certain nombre de fois la même action.</p>
|
|||
|
<ul>
|
|||
|
<li>Ajouter 5 fois 100 d'affilé</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [52]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">a</span> <span class="o">=</span> <span class="mi">2</span>
|
|||
|
<span class="k">print</span> <span class="s">"Au debut a vaut"</span><span class="p">,</span> <span class="n">a</span>
|
|||
|
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
|
|||
|
<span class="n">a</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="mi">100</span>
|
|||
|
<span class="k">print</span> <span class="s">"a vaut maintenant"</span><span class="p">,</span> <span class="n">a</span>
|
|||
|
<span class="k">print</span> <span class="s">"Finalement a vaut"</span><span class="p">,</span> <span class="n">a</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>Au debut a vaut 2
|
|||
|
a vaut maintenant 102
|
|||
|
a vaut maintenant 202
|
|||
|
a vaut maintenant 302
|
|||
|
a vaut maintenant 402
|
|||
|
a vaut maintenant 502
|
|||
|
Finalement a vaut 502
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li>On peut aussi parcourir les lettres d'un mot ou d'une phrase</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [55]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">phrase</span> <span class="o">=</span> <span class="s">"boujour toi"</span>
|
|||
|
<span class="k">print</span> <span class="s">"On enumere >>> "</span><span class="p">,</span> <span class="n">phrase</span>
|
|||
|
<span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">phrase</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="n">l</span>
|
|||
|
<span class="k">print</span> <span class="s">"Toutes les lettres ont été énumérées"</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>On enumere >>> boujour toi
|
|||
|
b
|
|||
|
o
|
|||
|
u
|
|||
|
j
|
|||
|
o
|
|||
|
u
|
|||
|
r
|
|||
|
|
|||
|
t
|
|||
|
o
|
|||
|
i
|
|||
|
Toutes les lettres ont été énumérées
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<ul>
|
|||
|
<li>Ou encore tous les éléments d'une liste</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [57]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">liste</span> <span class="o">=</span> <span class="p">[</span><span class="s">"premier element"</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="s">"coucou"</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s">"aie"</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
|
|||
|
<span class="k">print</span> <span class="s">"On enumère >>>"</span><span class="p">,</span> <span class="n">liste</span>
|
|||
|
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">liste</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="n">i</span>
|
|||
|
<span class="k">print</span> <span class="s">"Tout a été énuméré"</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>On enumère >>> ['premier element', 2, 'coucou', 1, 'aie', 0]
|
|||
|
premier element
|
|||
|
2
|
|||
|
coucou
|
|||
|
1
|
|||
|
aie
|
|||
|
0
|
|||
|
Tout a été énuméré
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Boucles-while">Boucles while<a class="anchor-link" href="#Boucles-while">¶</a></h2><p>En anglais, <code>while</code> signifie <strong>tant que</strong>. On l'utilisera quand on veut refaire quelque plusieurs fois <strong>tant que</strong> quelque chose n'est pas vrais.</p>
|
|||
|
<p>Ajouter 3 <strong>tant que</strong> que <code>u</code> n'a pas dépassé 19:</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [37]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">u</span> <span class="o">=</span> <span class="mi">2</span>
|
|||
|
<span class="k">while</span> <span class="n">u</span> <span class="o"><</span> <span class="mi">19</span><span class="p">:</span>
|
|||
|
<span class="n">u</span> <span class="o">=</span> <span class="n">u</span> <span class="o">+</span> <span class="mi">3</span>
|
|||
|
<span class="k">print</span> <span class="n">u</span>
|
|||
|
<span class="k">print</span> <span class="s">"u a depassé 50 et vaut"</span><span class="p">,</span> <span class="n">u</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>5
|
|||
|
8
|
|||
|
11
|
|||
|
14
|
|||
|
17
|
|||
|
20
|
|||
|
u a depassé 50 et vaut 20
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<p>Poser toujours la même question quand que l'utilisateur n'a pas bien répondu:</p>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [39]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre><span class="n">aPasTrouve</span> <span class="o">=</span> <span class="bp">True</span> <span class="c"># True signifie vrai en anglais.</span>
|
|||
|
<span class="k">while</span> <span class="n">aPasTrouve</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="s">"Quelle est la couleur du cheval blanc d'Henri 4?"</span>
|
|||
|
<span class="n">rep</span> <span class="o">=</span> <span class="nb">input</span><span class="p">()</span>
|
|||
|
<span class="k">if</span> <span class="n">rep</span> <span class="o">==</span> <span class="s">"blanc"</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="s">"Bravo!"</span>
|
|||
|
<span class="n">aPasTrouve</span> <span class="o">=</span> <span class="bp">False</span> <span class="c"># False signifie faux en anglais</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="k">print</span> <span class="s">"Non! Recommence!"</span>
|
|||
|
<span class="k">print</span> <span class="s">"Voila tu as réussi!"</span>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="output_wrapper">
|
|||
|
<div class="output">
|
|||
|
|
|||
|
|
|||
|
<div class="output_area"><div class="prompt"></div>
|
|||
|
<div class="output_subarea output_stream output_stdout output_text">
|
|||
|
<pre>Quelle est la couleur du cheval blanc d'Henri 4?
|
|||
|
"bleu"
|
|||
|
Non! Recommence!
|
|||
|
Quelle est la couleur du cheval blanc d'Henri 4?
|
|||
|
"jaune"
|
|||
|
Non! Recommence!
|
|||
|
Quelle est la couleur du cheval blanc d'Henri 4?
|
|||
|
"blanc"
|
|||
|
Bravo!
|
|||
|
Voila tu as réussi!
|
|||
|
</pre>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing text_cell rendered">
|
|||
|
<div class="prompt input_prompt">
|
|||
|
</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="text_cell_render border-box-sizing rendered_html">
|
|||
|
<h2 id="Fonction">Fonction<a class="anchor-link" href="#Fonction">¶</a></h2>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="cell border-box-sizing code_cell rendered">
|
|||
|
<div class="input">
|
|||
|
<div class="prompt input_prompt">In [ ]:</div>
|
|||
|
<div class="inner_cell">
|
|||
|
<div class="input_area">
|
|||
|
<div class=" highlight hl-ipython2"><pre>
|
|||
|
</pre></div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</body>
|
|||
|
</html>
|