2022-02-17 11:34:00 +00:00
{
"cells": [
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "2c522bc1",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
"# Étape 2: Variables, affectation et type"
]
},
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "7966e3c2",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
2022-02-18 09:31:39 +00:00
"### Trois types de variables\n",
"\n",
2022-02-18 10:14:22 +00:00
"Pour nous (humain) les trois variables qui suivent sont itdentiques"
]
},
{
"cell_type": "code",
2022-02-28 07:57:42 +00:00
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "d366babc",
"metadata": {},
2022-02-28 07:57:42 +00:00
"outputs": [],
2022-02-18 10:14:22 +00:00
"source": [
"a = 1\n",
"a"
]
},
{
"cell_type": "code",
2022-02-28 07:57:42 +00:00
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "87873ff4",
"metadata": {},
2022-02-28 07:57:42 +00:00
"outputs": [],
2022-02-18 10:14:22 +00:00
"source": [
"b = 1.0\n",
"b"
]
},
{
"cell_type": "code",
2022-02-28 07:57:42 +00:00
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "98f34ab7",
"metadata": {},
2022-02-28 07:57:42 +00:00
"outputs": [],
2022-02-18 10:14:22 +00:00
"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",
2022-02-28 07:57:42 +00:00
"execution_count": null,
2022-02-18 10:14:22 +00:00
"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": "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)"
2022-02-17 11:34:00 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "3288e311",
2022-02-17 11:34:00 +00:00
"metadata": {},
"outputs": [],
2022-02-18 10:14:22 +00:00
"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": {},
2022-02-17 11:34:00 +00:00
"source": []
},
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "8ef9fb28",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
2022-02-18 10:14:22 +00:00
"3. Expérimenter la fonction `float(...)`."
2022-02-17 11:34:00 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "d22272b4",
2022-02-17 11:34:00 +00:00
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "5b822091",
"metadata": {},
"source": [
"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": "332877f7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "da5cd3ea",
"metadata": {},
"source": [
"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",
2022-02-28 07:57:42 +00:00
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "afc36b4e",
"metadata": {},
2022-02-28 07:57:42 +00:00
"outputs": [],
2022-02-18 10:14:22 +00:00
"source": [
"reponse = input(\"Comment tu t'appelles?\")\n",
"reponse"
]
},
{
"cell_type": "markdown",
"id": "f7e096e1",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
2022-02-18 10:14:22 +00:00
"Quel est le type de la variable `reponse`"
2022-02-17 11:34:00 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "9518e549",
2022-02-17 11:34:00 +00:00
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "7aba1ac5",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
"## Exercices\n",
"\n",
"Dans les éxercices suivants vous devrez coder un programme qui fait ce qu'il est décrit. Vous pouvez les faire dans l'ordre que vous souhaitez."
]
},
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "47fa675c",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
"### Variation d'une grandeur\n",
"\n",
"Écrire un programme qui\n",
"\n",
" demande la valeur initiale\n",
" demande le taux d'évolution\n",
" affiche la valeur finale"
]
},
{
"cell_type": "code",
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "d885f2a5",
2022-02-17 11:34:00 +00:00
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "a368cdbe",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
"## Taux de variation\n",
"\n",
"Écrire un programme qui\n",
"\n",
" demande la valeur initiale\n",
" demande la valeur finale\n",
" affiche le taux d'évolution\n"
]
},
{
"cell_type": "code",
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "05f03257",
2022-02-17 11:34:00 +00:00
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "b540018d",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
"### Coordonnées du milieu\n",
"\n",
"Écrire un programme qui\n",
"\n",
" demande l'abscisse du point A\n",
" demande l'ordonnée du point A\n",
" demande l'abscisse du point B\n",
" demande l'ordonnée du point B\n",
" stock l'abscisse du milieu du segment [AB]\n",
" stock l'ordonnée du milieu du segment [AB]\n",
" affiche les coordonnées du milieu du segment [AB]\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
2022-02-18 10:14:22 +00:00
"id": "4ad529dc",
2022-02-17 11:34:00 +00:00
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
2022-02-18 10:14:22 +00:00
"id": "fdb3ba0c",
2022-02-17 11:34:00 +00:00
"metadata": {},
"source": [
"### Distance entre deux points\n",
"\n",
"Écrire un programme qui\n",
"\n",
" demande l'abscisse du point A\n",
" demande l'ordonnée du point A\n",
" demande l'abscisse du point B\n",
" demande l'ordonnée du point B\n",
" affiche la distance AB\n",
" \n",
"Pour calculer la racine carré, vous aurez besoin d'importer la fonction `sqrt`. Pour cela, votre programme devra commencer par la ligne suivante\n",
"\n",
" from math import sqrt"
]
2022-02-28 07:57:42 +00:00
},
{
"cell_type": "code",
"execution_count": null,
"id": "aae82c94",
"metadata": {},
"outputs": [],
"source": []
2022-02-17 11:34:00 +00:00
}
],
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}