Compare commits
6 Commits
411b7c6022
...
83d6636512
Author | SHA1 | Date | |
---|---|---|---|
83d6636512 | |||
e0530f0e33 | |||
084db581d7 | |||
5b7a35fb77 | |||
dbb74b63b7 | |||
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": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a895ccc3",
|
||||
"id": "82bb037d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Étape 1: Tour d'horizon\n",
|
||||
@ -11,7 +11,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "74bf75e9",
|
||||
"id": "a09120aa",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Decrire un programme\n",
|
||||
@ -21,7 +21,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "473bc947",
|
||||
"id": "ce34c464",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Programme 1"
|
||||
@ -30,7 +30,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "00e17aa0",
|
||||
"id": "6c462cdd",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@ -50,7 +50,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "114e94e6",
|
||||
"id": "b766a901",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Description"
|
||||
@ -58,13 +58,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "5542b9fd",
|
||||
"id": "9aa07472",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2261d0a8",
|
||||
"id": "6705ac53",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Programme 2"
|
||||
@ -73,7 +73,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "55d73535",
|
||||
"id": "7c20ebd3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -88,7 +88,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4bf64258",
|
||||
"id": "37efc7f9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Description"
|
||||
@ -96,13 +96,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "e289dc8c",
|
||||
"id": "0f5661ea",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "248c968b",
|
||||
"id": "779b8f5e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Programme 3\n"
|
||||
@ -111,7 +111,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b7a54d74",
|
||||
"id": "62ff525c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -124,7 +124,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "11c8e906",
|
||||
"id": "13ebd340",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Description"
|
||||
@ -132,13 +132,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "d86c1c23",
|
||||
"id": "429f7854",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0387ca4c",
|
||||
"id": "244bd147",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Modifier le programme de la momie\n",
|
||||
@ -152,8 +152,8 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "946e7e2b",
|
||||
"execution_count": null,
|
||||
"id": "8c4cabd7",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@ -161,22 +161,26 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"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",
|
||||
"Une momie attaque!\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",
|
||||
"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. Laquelle ouvres-tu?2\n",
|
||||
"Il y a 3 portes devant toi.\n",
|
||||
"Laquelle ouvres-tu?3\n",
|
||||
"Une momie attaque!\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",
|
||||
"Le jeu est fini, ton score est de 1\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",
|
||||
"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",
|
||||
"\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",
|
||||
" \n",
|
||||
" \n",
|
||||
@ -208,13 +213,12 @@
|
||||
" score = score + 1\n",
|
||||
"\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",
|
||||
"id": "89a3387e",
|
||||
"id": "4adb232c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"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",
|
||||
"id": "8d30a8f4",
|
||||
"id": "e360a730",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"*Variante 1* Modifier le programme pour que chaque ouverture de porte sans momie rapporte 10 points"
|
||||
@ -235,14 +239,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c1b6fc56",
|
||||
"id": "cdf9574f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "59ca0f04",
|
||||
"id": "bf70e6c4",
|
||||
"metadata": {},
|
||||
"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."
|
||||
@ -251,14 +255,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c8756d74",
|
||||
"id": "20e5169e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "524c50c7",
|
||||
"id": "7b0a44c8",
|
||||
"metadata": {},
|
||||
"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."
|
||||
@ -267,14 +271,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "83ca9834",
|
||||
"id": "4d363605",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3c1d61e9",
|
||||
"id": "470dee5f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"---\n",
|
||||
@ -283,7 +287,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e89d33f2",
|
||||
"id": "3836b2cb",
|
||||
"metadata": {},
|
||||
"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."
|
||||
@ -292,14 +296,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "22fc7fcf",
|
||||
"id": "5542e10a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2857505d",
|
||||
"id": "c36ead34",
|
||||
"metadata": {},
|
||||
"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."
|
||||
@ -308,14 +312,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "778a6605",
|
||||
"id": "739845b3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "993bc79b",
|
||||
"id": "30099d48",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"*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",
|
||||
"execution_count": null,
|
||||
"id": "7d4b48e6",
|
||||
"id": "26496d02",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3a1cc9d1",
|
||||
"id": "67564a0e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Variante 7 Étonnez nous avec une variante bien à vous!"
|
||||
@ -340,14 +344,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5df00726",
|
||||
"id": "05ab2d60",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f7aff6d5",
|
||||
"id": "99b5faf1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Bilan\n",
|
||||
@ -357,7 +361,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "e1605a82",
|
||||
"id": "935c6a7a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\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": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "431d820f",
|
||||
"id": "2c522bc1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Étape 2: Variables, affectation et type"
|
||||
@ -10,55 +10,317 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "68735bc5",
|
||||
"id": "7966e3c2",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Trois types de variables"
|
||||
"### Trois types de variables\n",
|
||||
"\n",
|
||||
"Pour nous (humain) les trois variables qui suivent sont itdentiques"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "d366babc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"a = 1\n",
|
||||
"a"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "87873ff4",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1.0"
|
||||
]
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"b = 1.0\n",
|
||||
"b"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "98f34ab7",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'1'"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"c = \"1\"\n",
|
||||
"c"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a1296b4f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Mais pour Python ce sont trois choses très différentes. Le premier est un **entier**, le deuxième est un **flottant** (nombre à virgule) et le dernier est une **chaine de caractères**."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a65d6da0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"1. Trier les variables suivantes en fonction de leur type"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "86571601",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"a = 3\n",
|
||||
"b = 4.5\n",
|
||||
"c = \"coucou\"\n",
|
||||
"d = \"6\"\n",
|
||||
"e = 8\n",
|
||||
"f = 5.0\n",
|
||||
"g = \"09\"\n",
|
||||
"h = \"0.4\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "708fea37",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Les entiers:\n",
|
||||
"Les flottants:\n",
|
||||
"Les chaines de caractères:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1cb8c216",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Il est possible de transformer les types. Pour cela, Python utilise les trois fonctions suivantes\n",
|
||||
"\n",
|
||||
"- `int(...)`\n",
|
||||
"- `str(...)`\n",
|
||||
"- `float(...)`\n",
|
||||
"\n",
|
||||
"2. Quelques exemples d'utilisation de la fonction `int(...)`. Les exécuter."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "bb073084",
|
||||
"id": "d5643413",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"int(a)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "8cce59f4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"int(b)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "67595ac0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"int(c)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "730d8ec6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"int(d)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3288e311",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"int(g)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "fa9adefe",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"En quoi la fonction `int(...)` tranforme-t-elle les variables?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "46b49780",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8ef9fb28",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Expérimenter la fonction `float(...)`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d22272b4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a8e5dc45",
|
||||
"id": "5b822091",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"`input` donne une chaine de caractère. Comment la transformer en int ou float"
|
||||
"En quoi la fonction `float(...)` tranforme-t-elle les variables?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "2cc489e3",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5da8293d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Expérimenter la fonction `str(...)`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "549afdb8",
|
||||
"id": "332877f7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ef52a1e0",
|
||||
"id": "da5cd3ea",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Opérations entre les types"
|
||||
"En quoi la fonction `str(...)` tranforme-t-elle les variables?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "8bcf3f94",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3f3ea6f9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"4. La fonction `input(...)` affiche du texte et attend un réponse."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "afc36b4e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Comment tu t'appelles?fjdsklmq\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'fjdsklmq'"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"reponse = input(\"Comment tu t'appelles?\")\n",
|
||||
"reponse"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f7e096e1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Quel est le type de la variable `reponse`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0fa1ffb7",
|
||||
"id": "9518e549",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "679b714c",
|
||||
"id": "7aba1ac5",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Exercices\n",
|
||||
@ -68,7 +330,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "39db342d",
|
||||
"id": "47fa675c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Variation d'une grandeur\n",
|
||||
@ -83,14 +345,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "142f5abd",
|
||||
"id": "d885f2a5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "35b73400",
|
||||
"id": "a368cdbe",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Taux de variation\n",
|
||||
@ -105,14 +367,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e7fb7e8e",
|
||||
"id": "05f03257",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "16e4cab9",
|
||||
"id": "b540018d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Coordonnées du milieu\n",
|
||||
@ -132,14 +394,14 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e3766249",
|
||||
"id": "4ad529dc",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "00c3137a",
|
||||
"id": "fdb3ba0c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Distance entre deux points\n",
|
||||
|
BIN
2nd/13_Programmation/3B_conditions.pdf
Normal file
BIN
2nd/13_Programmation/3B_conditions.pdf
Normal file
Binary file not shown.
39
2nd/13_Programmation/3B_conditions.tex
Normal file
39
2nd/13_Programmation/3B_conditions.tex
Normal file
@ -0,0 +1,39 @@
|
||||
\documentclass[a4paper,10pt]{article}
|
||||
\usepackage{myXsim}
|
||||
|
||||
\author{Benjamin Bertrand}
|
||||
\title{Programmation - Cours}
|
||||
\date{Février 2022}
|
||||
|
||||
\pagestyle{empty}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
\setcounter{section}{2}
|
||||
|
||||
\section{Conditions \lstinline{if/elif/else}}
|
||||
|
||||
Quand on veut gérer différent cas de figure, on utilise les mots clés \lstinline{if/elif/else}.
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.8\linewidth}
|
||||
\begin{lstlisting}
|
||||
age = str(input{Quel age as tu?})
|
||||
if age < 2: # si
|
||||
print("Tu es un bébé") # alors
|
||||
elif age < 18: #sinon si
|
||||
print("Tu n'es pas majeur") # alors
|
||||
print("Tu peux passer le permis")
|
||||
elif age < 50: #sinon si
|
||||
print("Tu as moins de la moitier d'un siècle") #alors
|
||||
else: #sinon
|
||||
print("Plus d'un demi siècle!")
|
||||
print("J'ai plus rien à dire")\end{lstlisting}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
|
||||
\paragraph{Remarque:} Il faut faire attention à l'indentation. C'est elle qui détermine où s'arrête le alors.
|
||||
|
||||
|
||||
\end{document}
|
@ -30,12 +30,12 @@
|
||||
"a = str(input(\"Choisir un nombre (a): \"))\n",
|
||||
"b = str(input(\"Choisir un autre nombre(b): \"))\n",
|
||||
"\n",
|
||||
"if a > b: # Si\n",
|
||||
" print(\"a plus grand que b\")\n",
|
||||
"if a < 10: # Si\n",
|
||||
" print(\"a est plus petit que 10\")\n",
|
||||
"elif a == b: # Sinon si\n",
|
||||
" print(\"a est égal à b\")\n",
|
||||
"else: # Sinon\n",
|
||||
" print(\"a est plus petit que b\")"
|
||||
" print(\"J'ai rien à dire\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -50,15 +50,57 @@
|
||||
"cell_type": "markdown",
|
||||
"id": "21e86bf8",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
"source": [
|
||||
"1. Un musée accorde des tarifs réduits aux groupes contenant au minimum 6 personnes de plus de 18 ans. Un informaticien du musée veut écrire un programme Python pour les clients qui achètent des billets en ligne. Ce programme doit demander au client le nombre d’adultes de plus de 18 ans du groupe puis afficher, suivant la réponse du client, l’une des deux phrases suivantes :\n",
|
||||
"\n",
|
||||
"- Vous avez droit au tarif Groupe !\n",
|
||||
"- Vous n’avez pas droit au tarif Groupe !\n",
|
||||
" \n",
|
||||
"L’informaticien a commencé à écrire le programme ci-dessous. Complétez-le :"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "f719d9ac",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Combien ...12\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"nombre_adulte = int(input(\"Combien ...\"))\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bd8f17d8",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. À l'achat d'une voiture neuve, l'état applique un malus écologique. C'est une taxe qui dépend de la quantité de CO2 rejeté par le véhicule. Voici quelques montants de cette taxe\n",
|
||||
"\n",
|
||||
"| Emission de C02 (g/km) | Montant du malus 2022 |\n",
|
||||
"|------------------------|-----------------------|\n",
|
||||
"| Moins de 127 | 0 |\n",
|
||||
"| De 128 à 151 | 1074 |\n",
|
||||
"| De 152 à 200 | 18 188 |\n",
|
||||
"| De 201 à 224 | 36 447 |\n",
|
||||
"| Plus de 225 | 40 000 |\n",
|
||||
"\n",
|
||||
"Écrire un programme qui demande l'emission du véhicule et qui affiche le montant du malus."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f719d9ac",
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"id": "e07500c9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
@ -67,7 +109,7 @@
|
||||
"id": "56711adc",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. **Questions flashs et correction automatique**\n",
|
||||
"3. **Questions flashs et correction automatique**\n",
|
||||
"\n",
|
||||
"Préparer une série de 4 questions flashs simples où la réponse est un nombre ou un mot. Écrire un programme qui demande une réponse aux questions flashs et qui dit si oui ou non la réponse est juste."
|
||||
]
|
||||
@ -93,15 +135,57 @@
|
||||
"id": "a140ea9c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"==, !=, <, >, <= et >="
|
||||
"En anglais, `True` signifie `vrai` et `False` signifie `faux`.\n",
|
||||
"\n",
|
||||
"Quelques opérateurs pour faire des comparaison entre nombres"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 3,
|
||||
"id": "b60a11dd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"True\n",
|
||||
"False\n",
|
||||
"False\n",
|
||||
"True\n",
|
||||
"True\n",
|
||||
"True\n",
|
||||
"True\n",
|
||||
"False\n",
|
||||
"False\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(2 == 2)\n",
|
||||
"print(2 == 3)\n",
|
||||
"print(2 != 2)\n",
|
||||
"print(10 != 5)\n",
|
||||
"print(4 < 5)\n",
|
||||
"print(4 <= 4)\n",
|
||||
"print(34 > 2)\n",
|
||||
"print(34 > 50)\n",
|
||||
"print(5 >= 10)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a801961d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Faire la liste des opérateurs et écrire une phrase pour décrire ce qu'ils signifie."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "7706dd5d",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
@ -109,7 +193,7 @@
|
||||
"id": "a4a0f415",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"not, and et or"
|
||||
"Pour combiner plusieur condition, on peut utiliser les mots clés `not` (pas), `and` (et) et `or` (ou)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -118,6 +202,21 @@
|
||||
"id": "3f3512da",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(2 == 2 and 4 == 4)\n",
|
||||
"print(2 == )"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "acee5b14",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "565d9da6",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
|
BIN
2nd/13_Programmation/4B_boucle_for.pdf
Normal file
BIN
2nd/13_Programmation/4B_boucle_for.pdf
Normal file
Binary file not shown.
54
2nd/13_Programmation/4B_boucle_for.tex
Normal file
54
2nd/13_Programmation/4B_boucle_for.tex
Normal file
@ -0,0 +1,54 @@
|
||||
\documentclass[a4paper,10pt]{article}
|
||||
\usepackage{myXsim}
|
||||
|
||||
\author{Benjamin Bertrand}
|
||||
\title{Programmation - Cours}
|
||||
\date{Février 2022}
|
||||
|
||||
\pagestyle{empty}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
\setcounter{section}{3}
|
||||
|
||||
\section{Boucle \lstinline{for}}
|
||||
|
||||
Quand on veut \textbf{faire} quelque chose un nombre de foi connus quelque chose, on utilise une boucle \lstinline{for}.
|
||||
|
||||
\begin{multicols}{2}
|
||||
\begin{minipage}{0.8\linewidth}
|
||||
\begin{lstlisting}
|
||||
for i in range(3):
|
||||
print("Coucou")\end{lstlisting}
|
||||
Le programme va afficher
|
||||
\vspace{2cm}
|
||||
\end{minipage}
|
||||
|
||||
\begin{minipage}{0.8\linewidth}
|
||||
\begin{lstlisting}
|
||||
somme = 0
|
||||
for i in range(4):
|
||||
somme = somme + i
|
||||
print(somme)\end{lstlisting}
|
||||
Le programme va afficher
|
||||
\vspace{1cm}
|
||||
|
||||
Tableau des variables
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{c|c}
|
||||
i & somme \\
|
||||
\hline
|
||||
& \\
|
||||
& \\
|
||||
& \\
|
||||
\end{tabular}
|
||||
\end{center}
|
||||
|
||||
\end{minipage}
|
||||
\end{multicols}
|
||||
|
||||
\afaire{Prévoir ce que vont afficher ces deux programmes et compléter le tableau des variables}
|
||||
|
||||
\end{document}
|
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
|
||||
:modified: 2022-02-17
|
||||
:modified: 2022-02-18
|
||||
:authors: Benjamin Bertrand
|
||||
:tags: Python
|
||||
: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.
|
||||
|
||||
.. image:: ./1B_momie.pdf
|
||||
:height: 200px
|
||||
:alt: Décortication d'un programme Python
|
||||
|
||||
|
||||
Étape 2: Variables, affectation et type
|
||||
---------------------------------------
|
||||
|
||||
@ -62,14 +67,33 @@ Types de données: int, float et string -> input donne un string qu'il est parfo
|
||||
Opérations suivant les types de données
|
||||
Traduction algo en français en programme en python
|
||||
|
||||
|
||||
Bilan:
|
||||
|
||||
.. image:: ./2B_variables.pdf
|
||||
:height: 200px
|
||||
:alt: Les types de variables
|
||||
|
||||
Étape 3: Conditions if
|
||||
----------------------
|
||||
|
||||
`Conditions if <./3E_conditions.ipynb>`_
|
||||
|
||||
Bilan:
|
||||
|
||||
.. image:: ./3B_conditions.pdf
|
||||
:height: 200px
|
||||
:alt: Les conditions
|
||||
|
||||
Étape 4: Boucle for
|
||||
-------------------
|
||||
|
||||
Bilan:
|
||||
|
||||
.. image:: ./4B_boucle_for.pdf
|
||||
:height: 200px
|
||||
:alt: Bilan sur les boucles for
|
||||
|
||||
Étape 5: Boucle While
|
||||
---------------------
|
||||
|
||||
|
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
|
||||
frame=single, % adds a frame around the coden,
|
||||
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
|
||||
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
|
||||
% numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
|
||||
numberstyle=\tiny\color{gray}, % 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))
|
||||
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
|
||||
showstringspaces=false, % underline spaces within strings only
|
||||
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
|
||||
stringstyle=\color{green},
|
||||
%stepnumber=2, % the step between two line-numbers. If it's 1, each line will be numbered
|
||||
stringstyle=\color{purple},
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user