Feat(1ST): TP python sur les boucles
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
809c20cc21
commit
f6a60cf3b9
|
@ -0,0 +1,306 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c66ea101",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Programmation et suites\n",
|
||||
"\n",
|
||||
"La programmation est un outil efficace pour calculer les termes d'une suite. C'est ce que nous allons apprendre à utiliser."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e7a96b1f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Calcul termes à termes\n",
|
||||
"\n",
|
||||
"On reprend notre exemple de l'étude de l'épidémie de Covid\n",
|
||||
"\n",
|
||||
"Sauf mention explicite, les questions suivantes devront être répondu en utilisant Python.\n",
|
||||
"\n",
|
||||
"### Premier modèle - arthimétique\n",
|
||||
"\n",
|
||||
"On suppose que le nombre de malades est modélisé par une suite arithmétique de raison +28 et de premier terme 130 (ce qui correspond à la date du 1/03/2020).\n",
|
||||
"\n",
|
||||
"1.Calculer le nombre de malade le 2/03/2020"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e54fa4a8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9936312e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Calculer le nombre de malade le 3/03/2020"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e7059cf4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2a26f718",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Calculer le nombre de malade le 10/03/2020"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "bf3d5969",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "57369bfc",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Deuxième modèle - géométrique\n",
|
||||
"\n",
|
||||
"On suppose que le nombre de malades est modélisé par une suite géométrique de raison x1.64 et de premier terme 130 (correspondant à la date du 01/03/2020)\n",
|
||||
"\n",
|
||||
"1. Calculer le nombre de malade le 2/03/2020"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b4f3efd7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "96e8cd82",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Calculer le nombre de malade le 3/03/2020"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "05f6f285",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2b46ca12",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Calculer le nombre de malade le 10/03/2020"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "1d9709a9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f9b84648",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Répétitions finies - Boucle for\n",
|
||||
"\n",
|
||||
"Le travail initié dans la partie précédente est répétitive surtout si l'on souhaite calculer le nombre de malades à la fin du mois (le 31/03/2020) ou plus tard.\n",
|
||||
"\n",
|
||||
"Quand on fait plusieur fois la même chose, on peut utiliser un boucle `for` en python. Voici un exemple de son utilisation:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "b96aca04",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"u = 3\n",
|
||||
"for i in range(10):\n",
|
||||
" u = u + 5 "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f2106ede",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"1. Que fait le programme précédent? Combien vaut `u` à la fin du programme? Quelle type de suite peut modéliser le contenu de la variable `u` (vous préciserez les paramètres)?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "41396015",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "03289e29",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Afficher la variable `somme` pour vérfier vos suppositions."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "416f8bb9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5f7dfe3c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Adapter le programme précédent pour calculer le nombre de malade au 16/03/2020 avec le modèle arithmétique."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c829159a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "55791f40",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"4. Quelle sera le nombre de malade avec le 31/03/2020 avec le modèle géométrique?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ed17e2da",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e337d3ce",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Répétition bornées - Boucle While\n",
|
||||
"\n",
|
||||
"Il est possible d'utiliser un autre type de boucles, les boucles `while`. `while` signifie **tant que** en anglais.\n",
|
||||
"\n",
|
||||
"À la différence des boucles `for` où l'on rentre un nombre de répétitions, les boucles `while` s'arrète à une condition donnée.\n",
|
||||
"\n",
|
||||
"Voici un exemple."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "0144ea7c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"jour = 0\n",
|
||||
"u = 3\n",
|
||||
"while u < 30:\n",
|
||||
" u = u*2\n",
|
||||
" jour = jour + 1\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "53eff1a1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"1. Que fait le programme précédent? Combien vaut `u` à la fin? Combien vaut `jour`? Quelle type de suite peut modéliser le contenu de la variable `u` (vous préciserez les paramètres)?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "e752f3cd",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3283fa60",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Adapter le programme précédent pour calculer le nombre de jours avant que le nombre de malades dépasse 1000 avec la suite arithmétique."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fef6fcb3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b5ff5bbb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Adapter le programme pour calculer le nombre de jours avant que le nombre de malades dépasse 100 000 avec la suite géométrique."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "156707ce",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
Loading…
Reference in New Issue