From e0530f0e33c058c690e882390eff031af6dfe56d Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 18 Feb 2022 11:14:22 +0100 Subject: [PATCH] Feat: fin du TP sur les variables --- 2nd/13_Programmation/2E_variables.ipynb | 316 +++++++++++++++++++++--- 1 file changed, 288 insertions(+), 28 deletions(-) diff --git a/2nd/13_Programmation/2E_variables.ipynb b/2nd/13_Programmation/2E_variables.ipynb index a16a70a..3cc50fa 100644 --- a/2nd/13_Programmation/2E_variables.ipynb +++ b/2nd/13_Programmation/2E_variables.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "70d4a95c", + "id": "2c522bc1", "metadata": {}, "source": [ "# Étape 2: Variables, affectation et type" @@ -10,57 +10,317 @@ }, { "cell_type": "markdown", - "id": "01f35556", + "id": "7966e3c2", "metadata": {}, "source": [ "### Trois types de variables\n", "\n", - "En informatique " + "Pour nous (humain) les trois variables qui suivent sont itdentiques" ] }, { "cell_type": "code", - "execution_count": null, - "id": "3dfc05ea", + "execution_count": 1, + "id": "d366babc", "metadata": {}, - "outputs": [], - "source": [] + "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": "07c32553", + "id": "a1296b4f", "metadata": {}, "source": [ - "`input` donne une chaine de caractère. Comment la transformer en int ou float" + "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": "code", - "execution_count": null, - "id": "b11ee13b", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", - "id": "978e9480", + "id": "a65d6da0", "metadata": {}, "source": [ - "Opérations entre les types" + "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": "4a7ca5f9", + "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": "192bd626", + "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", + "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": "9518e549", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "7aba1ac5", "metadata": {}, "source": [ "## Exercices\n", @@ -70,7 +330,7 @@ }, { "cell_type": "markdown", - "id": "d4e53096", + "id": "47fa675c", "metadata": {}, "source": [ "### Variation d'une grandeur\n", @@ -85,14 +345,14 @@ { "cell_type": "code", "execution_count": null, - "id": "eeb479d2", + "id": "d885f2a5", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "705276dc", + "id": "a368cdbe", "metadata": {}, "source": [ "## Taux de variation\n", @@ -107,14 +367,14 @@ { "cell_type": "code", "execution_count": null, - "id": "b1a4755a", + "id": "05f03257", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "1037725f", + "id": "b540018d", "metadata": {}, "source": [ "### Coordonnées du milieu\n", @@ -134,14 +394,14 @@ { "cell_type": "code", "execution_count": null, - "id": "c2b735ba", + "id": "4ad529dc", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", - "id": "4d3ce1bf", + "id": "fdb3ba0c", "metadata": {}, "source": [ "### Distance entre deux points\n",