Feat: deux premiers bilans sur la programmation
This commit is contained in:
parent
411b7c6022
commit
0329b97ff4
BIN
2nd/13_Programmation/1B_momie.pdf
Normal file
BIN
2nd/13_Programmation/1B_momie.pdf
Normal file
Binary file not shown.
38
2nd/13_Programmation/1B_momie.tex
Normal file
38
2nd/13_Programmation/1B_momie.tex
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
\documentclass[a4paper,10pt]{article}
|
||||||
|
\usepackage{myXsim}
|
||||||
|
|
||||||
|
\author{Benjamin Bertrand}
|
||||||
|
\title{Programmation - Cours}
|
||||||
|
\date{Février 2022}
|
||||||
|
|
||||||
|
\pagestyle{empty}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\maketitle
|
||||||
|
|
||||||
|
\section{Programme Python}
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
%\includegraphics[scale=0.6]{./fig/pgm_momie}
|
||||||
|
\begin{minipage}{0.8\linewidth}
|
||||||
|
\lstinputlisting[language=Python]{./momie.py}
|
||||||
|
\end{minipage}
|
||||||
|
\end{center}
|
||||||
|
|
||||||
|
Contenu du programme
|
||||||
|
|
||||||
|
\afaire{Relever les mots clés, les opérateurs, les variables et les fonctions dans le programme.}
|
||||||
|
|
||||||
|
\begin{itemize}
|
||||||
|
\item Les mots clés (en vert gras)
|
||||||
|
\vspace{2cm}
|
||||||
|
\item Les opérateurs (en rose)
|
||||||
|
\vspace{2cm}
|
||||||
|
\item Les variables (en noir)
|
||||||
|
\vspace{2cm}
|
||||||
|
\item Les fonctions (en vert)
|
||||||
|
\vspace{2cm}
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
\end{document}
|
@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "a895ccc3",
|
"id": "82bb037d",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# Étape 1: Tour d'horizon\n",
|
"# Étape 1: Tour d'horizon\n",
|
||||||
@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "74bf75e9",
|
"id": "a09120aa",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Decrire un programme\n",
|
"## Decrire un programme\n",
|
||||||
@ -21,7 +21,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "473bc947",
|
"id": "ce34c464",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Programme 1"
|
"### Programme 1"
|
||||||
@ -30,7 +30,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 6,
|
||||||
"id": "00e17aa0",
|
"id": "6c462cdd",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "114e94e6",
|
"id": "b766a901",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Description"
|
"Description"
|
||||||
@ -58,13 +58,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "raw",
|
"cell_type": "raw",
|
||||||
"id": "5542b9fd",
|
"id": "9aa07472",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "2261d0a8",
|
"id": "6705ac53",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Programme 2"
|
"### Programme 2"
|
||||||
@ -73,7 +73,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "55d73535",
|
"id": "7c20ebd3",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -88,7 +88,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "4bf64258",
|
"id": "37efc7f9",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Description"
|
"Description"
|
||||||
@ -96,13 +96,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "raw",
|
"cell_type": "raw",
|
||||||
"id": "e289dc8c",
|
"id": "0f5661ea",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "248c968b",
|
"id": "779b8f5e",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Programme 3\n"
|
"### Programme 3\n"
|
||||||
@ -111,7 +111,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "b7a54d74",
|
"id": "62ff525c",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -124,7 +124,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "11c8e906",
|
"id": "13ebd340",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Description"
|
"Description"
|
||||||
@ -132,13 +132,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "raw",
|
"cell_type": "raw",
|
||||||
"id": "d86c1c23",
|
"id": "429f7854",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "0387ca4c",
|
"id": "244bd147",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Modifier le programme de la momie\n",
|
"## Modifier le programme de la momie\n",
|
||||||
@ -152,8 +152,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": null,
|
||||||
"id": "946e7e2b",
|
"id": "8c4cabd7",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
@ -161,22 +161,26 @@
|
|||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...\n",
|
"Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...\n",
|
||||||
"Il y a 3 portes devant toi. Laquelle ouvres-tu?2\n",
|
"Il y a 3 portes devant toi.\n",
|
||||||
"Une momie attaque!\n",
|
"Laquelle ouvres-tu?3\n",
|
||||||
"Elle te touche une fois\n",
|
|
||||||
"Elle te touche une fois\n",
|
|
||||||
"Elle te touche une fois\n",
|
|
||||||
"Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...\n",
|
|
||||||
"Il y a 3 portes devant toi. Laquelle ouvres-tu?2\n",
|
|
||||||
"Rien! Tu as survécu à une porte en plus.\n",
|
"Rien! Tu as survécu à une porte en plus.\n",
|
||||||
"Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...\n",
|
"Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...\n",
|
||||||
"Il y a 3 portes devant toi. Laquelle ouvres-tu?2\n",
|
"Il y a 3 portes devant toi.\n",
|
||||||
|
"Laquelle ouvres-tu?3\n",
|
||||||
"Une momie attaque!\n",
|
"Une momie attaque!\n",
|
||||||
"Elle te touche une fois\n",
|
"Elle te touche une fois\n",
|
||||||
"Elle te touche une fois\n",
|
"Elle te touche une fois\n",
|
||||||
"Elle te touche une fois\n",
|
"Elle te touche une fois\n",
|
||||||
"T'es mort. Tu n'as plus de points de vie.\n",
|
"Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...\n",
|
||||||
"Le jeu est fini, ton score est de 1\n"
|
"Il y a 3 portes devant toi.\n",
|
||||||
|
"Laquelle ouvres-tu?3\n",
|
||||||
|
"Rien! Tu as survécu à une porte en plus.\n",
|
||||||
|
"Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...\n",
|
||||||
|
"Il y a 3 portes devant toi.\n",
|
||||||
|
"Laquelle ouvres-tu?3\n",
|
||||||
|
"Rien! Tu as survécu à une porte en plus.\n",
|
||||||
|
"Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...\n",
|
||||||
|
"Il y a 3 portes devant toi.\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -185,7 +189,8 @@
|
|||||||
"from random import randint\n",
|
"from random import randint\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def choisir_porte(nombre_portes):\n",
|
"def choisir_porte(nombre_portes):\n",
|
||||||
" porte_choisie = int(input(\"Il y a \" + str(nombre_portes) + \" portes devant toi. Laquelle ouvres-tu?\"))\n",
|
" print(\"Il y a \" + str(nombre_portes) + \" portes devant toi.\")\n",
|
||||||
|
" porte_choisie = int(input( \"Laquelle ouvres-tu?\"))\n",
|
||||||
" return porte_choisie\n",
|
" return porte_choisie\n",
|
||||||
" \n",
|
" \n",
|
||||||
" \n",
|
" \n",
|
||||||
@ -208,13 +213,12 @@
|
|||||||
" score = score + 1\n",
|
" score = score + 1\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(\"T'es mort. Tu n'as plus de points de vie.\")\n",
|
"print(\"T'es mort. Tu n'as plus de points de vie.\")\n",
|
||||||
"print(\"Le jeu est fini, ton score est de \", score)\n",
|
"print(\"Le jeu est fini, ton score est de \", score)"
|
||||||
" "
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "89a3387e",
|
"id": "4adb232c",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Maintenant que vous avez un peu joué à ce jeu. Vous allez créer des variantes de ce jeu. \n",
|
"Maintenant que vous avez un peu joué à ce jeu. Vous allez créer des variantes de ce jeu. \n",
|
||||||
@ -226,7 +230,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "8d30a8f4",
|
"id": "e360a730",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"*Variante 1* Modifier le programme pour que chaque ouverture de porte sans momie rapporte 10 points"
|
"*Variante 1* Modifier le programme pour que chaque ouverture de porte sans momie rapporte 10 points"
|
||||||
@ -235,14 +239,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "c1b6fc56",
|
"id": "cdf9574f",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "59ca0f04",
|
"id": "bf70e6c4",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"*Variante 2* Modifier le programme pour que l'on commence avec 5 points de vie mais qu'il n'y ait que deux portes à chaque fois."
|
"*Variante 2* Modifier le programme pour que l'on commence avec 5 points de vie mais qu'il n'y ait que deux portes à chaque fois."
|
||||||
@ -251,14 +255,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "c8756d74",
|
"id": "20e5169e",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "524c50c7",
|
"id": "7b0a44c8",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"*Variante 3* On part fixe le nombre de porte à 3. Quelle est la probabilité de tomber sur un momie? Transformer le programme pour la probabilité de tomber sur un momie soit de 3/2."
|
"*Variante 3* On part fixe le nombre de porte à 3. Quelle est la probabilité de tomber sur un momie? Transformer le programme pour la probabilité de tomber sur un momie soit de 3/2."
|
||||||
@ -267,14 +271,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "83ca9834",
|
"id": "4d363605",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "3c1d61e9",
|
"id": "470dee5f",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"---\n",
|
"---\n",
|
||||||
@ -283,7 +287,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "e89d33f2",
|
"id": "3836b2cb",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"*Variante 4* Le programme comporte un gros bug. Il est possible de ne jamais être dévoré par la momie. Proposer une façon de corriger ce bug."
|
"*Variante 4* Le programme comporte un gros bug. Il est possible de ne jamais être dévoré par la momie. Proposer une façon de corriger ce bug."
|
||||||
@ -292,14 +296,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "22fc7fcf",
|
"id": "5542e10a",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "2857505d",
|
"id": "c36ead34",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"*Variante 5* Modifier le programme pour qu'à chaque fois que l'on tombe sur une momie. On ait une chance sur deux de perdre 1 point de vie et une chance sur 2 de ne perdre 2 points de vie."
|
"*Variante 5* Modifier le programme pour qu'à chaque fois que l'on tombe sur une momie. On ait une chance sur deux de perdre 1 point de vie et une chance sur 2 de ne perdre 2 points de vie."
|
||||||
@ -308,14 +312,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "778a6605",
|
"id": "739845b3",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "993bc79b",
|
"id": "30099d48",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"*Variante 6* Ajouter d'autres monstres cachés derière d'autres portes qui enlèves plus ou moins de points."
|
"*Variante 6* Ajouter d'autres monstres cachés derière d'autres portes qui enlèves plus ou moins de points."
|
||||||
@ -324,14 +328,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "7d4b48e6",
|
"id": "26496d02",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "3a1cc9d1",
|
"id": "67564a0e",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Variante 7 Étonnez nous avec une variante bien à vous!"
|
"Variante 7 Étonnez nous avec une variante bien à vous!"
|
||||||
@ -340,14 +344,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "5df00726",
|
"id": "05ab2d60",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "f7aff6d5",
|
"id": "99b5faf1",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Bilan\n",
|
"## Bilan\n",
|
||||||
@ -357,7 +361,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "raw",
|
"cell_type": "raw",
|
||||||
"id": "e1605a82",
|
"id": "935c6a7a",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"\n"
|
"\n"
|
||||||
|
BIN
2nd/13_Programmation/2B_variables.pdf
Normal file
BIN
2nd/13_Programmation/2B_variables.pdf
Normal file
Binary file not shown.
60
2nd/13_Programmation/2B_variables.tex
Normal file
60
2nd/13_Programmation/2B_variables.tex
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
\documentclass[a4paper,10pt]{article}
|
||||||
|
\usepackage{myXsim}
|
||||||
|
|
||||||
|
\author{Benjamin Bertrand}
|
||||||
|
\title{Programmation - Cours}
|
||||||
|
\date{Février 2022}
|
||||||
|
|
||||||
|
\pagestyle{empty}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\maketitle
|
||||||
|
\setcounter{section}{1}
|
||||||
|
|
||||||
|
\section{Types de variables}
|
||||||
|
|
||||||
|
Vous devez connaître trois types de variables
|
||||||
|
|
||||||
|
\begin{multicols}{3}
|
||||||
|
Les entiers
|
||||||
|
|
||||||
|
\begin{lstlisting}
|
||||||
|
a = 2\end{lstlisting}
|
||||||
|
|
||||||
|
Les flottants
|
||||||
|
|
||||||
|
\begin{lstlisting}
|
||||||
|
a = 2.2\end{lstlisting}
|
||||||
|
|
||||||
|
Les chaines de caractères
|
||||||
|
|
||||||
|
\begin{lstlisting}
|
||||||
|
a = "2"\end{lstlisting}
|
||||||
|
\end{multicols}
|
||||||
|
|
||||||
|
\bigskip
|
||||||
|
|
||||||
|
Le symbole \lstinline[ columns=fixed ]{=} affecte une valeur à une variable.
|
||||||
|
|
||||||
|
\bigskip
|
||||||
|
|
||||||
|
Quand c'est possible, des fonctions python permettent de transformer un type de variable en un autre.
|
||||||
|
|
||||||
|
\begin{itemize}
|
||||||
|
\item Transformer en entier: \lstinline[columns=fixed]{int(...)}
|
||||||
|
\item Transformer en flottant \lstinline[columns=fixed]{float(...)}
|
||||||
|
\item Transformer en chaine de caractères \lstinline[columns=fixed]{str(...)}
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
\bigskip
|
||||||
|
|
||||||
|
Deux fonctions pour interagir avec l'utilisateur du programme:
|
||||||
|
\begin{itemize}
|
||||||
|
\item \lstinline[ columns=fixed ]{print(...)}: affiche à l'écran ce qui lui est transmis dans les parenthèses.
|
||||||
|
\item \lstinline[columns=fixed]{input(...)}: affiche à l'écran ce qui lui est transmis dans les parenthèses, attend un réponse de l'utilisateur et retourne la réponse sous forme d'une chaine de caractères.
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\end{document}
|
@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "431d820f",
|
"id": "70d4a95c",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# Étape 2: Variables, affectation et type"
|
"# Étape 2: Variables, affectation et type"
|
||||||
@ -10,23 +10,25 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "68735bc5",
|
"id": "01f35556",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Trois types de variables"
|
"### Trois types de variables\n",
|
||||||
|
"\n",
|
||||||
|
"En informatique "
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "bb073084",
|
"id": "3dfc05ea",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "a8e5dc45",
|
"id": "07c32553",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"`input` donne une chaine de caractère. Comment la transformer en int ou float"
|
"`input` donne une chaine de caractère. Comment la transformer en int ou float"
|
||||||
@ -35,14 +37,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "549afdb8",
|
"id": "b11ee13b",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "ef52a1e0",
|
"id": "978e9480",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Opérations entre les types"
|
"Opérations entre les types"
|
||||||
@ -51,14 +53,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "0fa1ffb7",
|
"id": "4a7ca5f9",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "679b714c",
|
"id": "192bd626",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Exercices\n",
|
"## Exercices\n",
|
||||||
@ -68,7 +70,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "39db342d",
|
"id": "d4e53096",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Variation d'une grandeur\n",
|
"### Variation d'une grandeur\n",
|
||||||
@ -83,14 +85,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "142f5abd",
|
"id": "eeb479d2",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "35b73400",
|
"id": "705276dc",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Taux de variation\n",
|
"## Taux de variation\n",
|
||||||
@ -105,14 +107,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "e7fb7e8e",
|
"id": "b1a4755a",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "16e4cab9",
|
"id": "1037725f",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Coordonnées du milieu\n",
|
"### Coordonnées du milieu\n",
|
||||||
@ -132,14 +134,14 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"id": "e3766249",
|
"id": "c2b735ba",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "00c3137a",
|
"id": "4d3ce1bf",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Distance entre deux points\n",
|
"### Distance entre deux points\n",
|
||||||
|
BIN
2nd/13_Programmation/fig/pgm_momie.png
Normal file
BIN
2nd/13_Programmation/fig/pgm_momie.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
@ -2,7 +2,7 @@ Programmation
|
|||||||
#############
|
#############
|
||||||
|
|
||||||
:date: 2022-02-07
|
:date: 2022-02-07
|
||||||
:modified: 2022-02-17
|
:modified: 2022-02-18
|
||||||
:authors: Benjamin Bertrand
|
:authors: Benjamin Bertrand
|
||||||
:tags: Python
|
:tags: Python
|
||||||
:category: 2nd
|
:category: 2nd
|
||||||
@ -53,6 +53,11 @@ Au moins 10 minutes avant la fin de l'heure, on forcera les élèves à faire la
|
|||||||
|
|
||||||
Bilan: le programme de la momie avec les mots clé mis en valeur et décrit succinctement.
|
Bilan: le programme de la momie avec les mots clé mis en valeur et décrit succinctement.
|
||||||
|
|
||||||
|
.. image:: ./1B_momie.pdf
|
||||||
|
:height: 200px
|
||||||
|
:alt: Décortication d'un programme Python
|
||||||
|
|
||||||
|
|
||||||
Étape 2: Variables, affectation et type
|
Étape 2: Variables, affectation et type
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
@ -62,6 +67,11 @@ Types de données: int, float et string -> input donne un string qu'il est parfo
|
|||||||
Opérations suivant les types de données
|
Opérations suivant les types de données
|
||||||
Traduction algo en français en programme en python
|
Traduction algo en français en programme en python
|
||||||
|
|
||||||
|
.. image:: ./2B_variables.pdf
|
||||||
|
:height: 200px
|
||||||
|
:alt: Les types de variables
|
||||||
|
|
||||||
|
|
||||||
Étape 3: Conditions if
|
Étape 3: Conditions if
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
29
2nd/13_Programmation/momie.py
Normal file
29
2nd/13_Programmation/momie.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Programme de la momie - tiré du livre les maths ensembles et pour chacun
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
def choisir_porte(nombre_portes):
|
||||||
|
print("Il y a " + str(nombre_portes) + " portes devant toi.")
|
||||||
|
porte_choisie = int(input( "Laquelle ouvres-tu?"))
|
||||||
|
return porte_choisie
|
||||||
|
|
||||||
|
|
||||||
|
nombre_portes = 3
|
||||||
|
points_de_vie = 5
|
||||||
|
score = 0
|
||||||
|
degat_momie = 3
|
||||||
|
|
||||||
|
while points_de_vie > 0:
|
||||||
|
print("Tu arrives dans un long couloir et tu avances. Jusqu'à ce que...")
|
||||||
|
porte_momie = randint(0, nombre_portes)
|
||||||
|
porte_choisie = choisir_porte(nombre_portes)
|
||||||
|
if porte_choisie == porte_momie:
|
||||||
|
print("Une momie attaque!")
|
||||||
|
for i in range(degat_momie):
|
||||||
|
print("Elle te touche une fois")
|
||||||
|
points_de_vie = points_de_vie - 1
|
||||||
|
else:
|
||||||
|
print("Rien! Tu as survécu à une porte en plus.")
|
||||||
|
score = score + 1
|
||||||
|
|
||||||
|
print("T'es mort. Tu n'as plus de points de vie.")
|
||||||
|
print("Le jeu est fini, ton score est de ", score)
|
@ -30,18 +30,18 @@
|
|||||||
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
|
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
|
||||||
frame=single, % adds a frame around the coden,
|
frame=single, % adds a frame around the coden,
|
||||||
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
|
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
|
||||||
keywordstyle=\color{blue}, % keyword style
|
keywordstyle=\color{green}, % keyword style
|
||||||
language=Python, % the language of the code
|
language=Python, % the language of the code
|
||||||
morekeywords={*,...}, % if you want to add more keywords to the set
|
morekeywords={*,...}, % if you want to add more keywords to the set
|
||||||
% numbers=left, % where to put the line-numbers; possible values are (none, left, right)
|
numbers=left, % where to put the line-numbers; possible values are (none, left, right)
|
||||||
% numbersep=5pt, % how far the line-numbers are from the code
|
% numbersep=5pt, % how far the line-numbers are from the code
|
||||||
% numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
|
numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
|
||||||
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
|
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
|
||||||
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
|
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
|
||||||
showstringspaces=false, % underline spaces within strings only
|
showstringspaces=false, % underline spaces within strings only
|
||||||
showtabs=false, % show tabs within strings adding particular underscores
|
showtabs=false, % show tabs within strings adding particular underscores
|
||||||
stepnumber=2, % the step between two line-numbers. If it's 1, each line will be numbered
|
%stepnumber=2, % the step between two line-numbers. If it's 1, each line will be numbered
|
||||||
stringstyle=\color{green},
|
stringstyle=\color{purple},
|
||||||
tabsize=2, % sets default tabsize to 2 spaces
|
tabsize=2, % sets default tabsize to 2 spaces
|
||||||
%title=\tiny\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title
|
%title=\tiny\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user