Compare commits
3 Commits
ac4aa555b7
...
6174205816
Author | SHA1 | Date | |
---|---|---|---|
6174205816 | |||
8195d1ad59 | |||
c92d7bbbb7 |
@ -105,14 +105,7 @@
|
||||
\begin{exercise}[subtitle={Application web avec Bottle - requête POST}, step={2}, origin={Ma tête}, topics={ Interaction client-serveur }, tags={ HTTP, Flask }]
|
||||
Les requêtes POST envoient des informations au serveur. Ces informations sont le plus souvent envoyé à partir d'une formulaire HTML.
|
||||
|
||||
On reprend le code de la question \ref{bottle_base} de l'exercice précédent. Puis on ajoute à côté du script de notre application, le modèle suivant:
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\inputminted[bgcolor=base3,linenos]{html}{./scripts/modele_base.html}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
Ce modèle permettra d'avoir une structure HTML propre. Il n'y aura plus qu'à passer le contenu du body.
|
||||
On reprend le code de la question \ref{bottle_base} de l'exercice précédent.
|
||||
|
||||
\begin{enumerate}
|
||||
\item Supprimer la route \texttt{hello} et ajouter la route suivante
|
||||
@ -165,7 +158,7 @@
|
||||
\end{exercise}
|
||||
|
||||
|
||||
\begin{exercise}[subtitle={QCM}, step={2}, origin={Ma tête}, topics={ Interaction client-serveur }, tags={ HTTP, Flask }]
|
||||
\begin{exercise}[subtitle={QCM}, step={2}, origin={Annales}, topics={ Interaction client-serveur }, tags={ HTTP, Flask }]
|
||||
\begin{enumerate}
|
||||
\item Parmi GET et POST, quelle méthode d'envoi de formulaire crypte les informations envoyées au serveurs?
|
||||
\begin{tasks}(2)
|
||||
|
@ -2,7 +2,7 @@ Interaction client-serveur
|
||||
###########################
|
||||
|
||||
:date: 2023-01-03
|
||||
:modified: 2023-01-16
|
||||
:modified: 2023-01-22
|
||||
:authors: Benjamin Bertrand
|
||||
:tags: Http, Flask
|
||||
:category: 1NSI
|
||||
@ -31,8 +31,14 @@ Interaction client-serveur
|
||||
Progression
|
||||
===========
|
||||
|
||||
Étape 1: Étude des headers
|
||||
--------------------------
|
||||
Plan de travail
|
||||
|
||||
.. image:: ./plan_de_travail.pdf
|
||||
:height: 200px
|
||||
:alt: Plan de travail
|
||||
|
||||
Etape 1: requetes
|
||||
=================
|
||||
|
||||
Cours: rappels de ce qui a été déjà fait sur le web: client serveur, url, positionnement du protocole HTTP dans la stack web. Introduction des concepts requêtes/reponses.
|
||||
|
||||
@ -48,6 +54,11 @@ Bilan:
|
||||
:height: 200px
|
||||
:alt: Bilan sur les requêtes POST, les formulaires et les codes status du serveur
|
||||
|
||||
Etape 2: construction d'un serveur
|
||||
==================================
|
||||
|
||||
Étape 2: Construire un serveur web avec Flask
|
||||
---------------------------------------------
|
||||
Pour faire les exercices utilisant Bottle, il faut placer `le fichier bottle.py <https://raw.githubusercontent.com/bottlepy/bottle/master/bottle.py>`_ à côté de votre script.
|
||||
|
||||
|
||||
Etape 3: QCM type
|
||||
=================
|
||||
|
Binary file not shown.
@ -6,4 +6,4 @@ def get_formulaire():
|
||||
<input type='submit' value='Bonjour bottle !'/>
|
||||
</form>
|
||||
"""
|
||||
return template("modele_base.html", boby=formulaire)
|
||||
return formulaire
|
||||
|
@ -1,6 +1,6 @@
|
||||
@post('/formulaire')
|
||||
@post('/bonjour')
|
||||
def bonjour() :
|
||||
nom = bottle.request.forms.get('nom')
|
||||
body = "<p>Bonjour mon(a) che(è)r(e) " + nom + "</p>"
|
||||
|
||||
return template("modele_base.py", body=body)
|
||||
return body
|
||||
|
@ -1,4 +1,4 @@
|
||||
from botte import request, get
|
||||
from bottle import request, get
|
||||
|
||||
@get('/age')
|
||||
def age_de():
|
||||
@ -6,9 +6,9 @@ def age_de():
|
||||
name = request.query.name
|
||||
age = request.query.age
|
||||
|
||||
if age > 1:
|
||||
if int(age) > 1:
|
||||
return name + " a " + age + " ans."
|
||||
elif age <= 0:
|
||||
elif int(age) <= 0:
|
||||
return "Mouai..."
|
||||
else:
|
||||
return name + " a " + age + " an."
|
||||
|
14
1NSI/06_Listes_et_tuples/1B.tex
Normal file
14
1NSI/06_Listes_et_tuples/1B.tex
Normal file
@ -0,0 +1,14 @@
|
||||
\documentclass[a4paper,10pt]{article}
|
||||
\usepackage{myXsim}
|
||||
|
||||
\author{Benjamin Bertrand}
|
||||
\title{Listes et tuples - Cours}
|
||||
\date{janvier 2023}
|
||||
|
||||
\pagestyle{empty}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\end{document}
|
@ -0,0 +1,585 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ed3c16da",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Découverte des listes et des tuples\n",
|
||||
"\n",
|
||||
"## Mise en situation\n",
|
||||
"\n",
|
||||
"On souhaite écrire un programme qui fait une moyenne de notes.\n",
|
||||
"\n",
|
||||
"1. Écrire une fonction `moyenne3` qui prend en argument 3 notes et qui renvoie la moyenne de ces trois notes"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "352fd339",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# tests\n",
|
||||
"assert moyenne3(1, 2, 3) == 2\n",
|
||||
"assert moyenne3(10, 0, 5) == 5"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ddd2db52",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# fonction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3e58998e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "97396105",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Écrire une fonction `moyenne_question` qui prend en argument un nombre de notes puis renvoie la moyenne des notes entrée par l'utilisateur (avec input)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4dd1cb77",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# pas de tests à cause de l'utilisation du input"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "572a9917",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# fonction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "af965cbe",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "91486d89",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. On voudrait maintenant écrire une fonction qui prend en argument plusieurs notes (qu'on ne connait pas à l'avance) et qui renvoie la moyenne de ces notes. Quels sont les obstacles qui empêchent de réaliser une telle fonction?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "ac18a2ae",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "28501a12",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Les listes\n",
|
||||
"\n",
|
||||
"Les `list` sont un autre type de variable (au même titre que les `int`, `float`...). Ils ont la particularité de stocker un nombre arbitraire de variables. En voici des exemples"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0c8dd096",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"liste1 = [1, 2, 3, 4, 5]\n",
|
||||
"liste2 = [\"a\", \"c\" \"uio\", \"éé\"]\n",
|
||||
"liste3 = [-1, 2.2, \"uio\", 10, 100, \"1000\"] "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "28c340b2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(liste1)\n",
|
||||
"print(liste2)\n",
|
||||
"print(liste3)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9dd742c8",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Accéder à un élément de liste\n",
|
||||
"\n",
|
||||
"Pour accéder à un élément particulier d'une liste, on utilise les crochets`[]`.\n",
|
||||
"\n",
|
||||
"1. Deviner ce qui va être afficher par les commandes ci-dessous avant de l'exécuter."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "87fc0d29",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(liste1[3])\n",
|
||||
"print(liste2[2])\n",
|
||||
"print(liste3[0])\n",
|
||||
"print(liste1[-1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "61cb8afe",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Écrire les commandes pour accéder au nombre 2 de la liste1, \"éé\" de la liste2 et \"uio\" de la liste3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f11b02a8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "cadb6818",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Que se passe-t-il quand on essayer d'accéder à une valeur qui n'existe pas?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "37903285",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "raw",
|
||||
"id": "9a0e4586",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "da97681e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"4. On peut aussi modifier un élément d'une liste"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f594935a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"liste1[1] = \"azert\"\n",
|
||||
"print(list1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bd595043",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"5. Construire une liste avec les nombres pairs inférieur à 10. Puis modifier la pour que les multiples de 4 soient remplacés par \"a\"."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4677cbb0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f08d4c53",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Ajouter/supprimer des éléments\n",
|
||||
"\n",
|
||||
"Pour ajouter des éléments, on utilise la méthode `.append(...)`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ff4e90a0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"liste3 = [-1, 2.2, \"uio\", 10, 100, \"1000\"]\n",
|
||||
"print(liste3)\n",
|
||||
"liste3.append(\"nsi\")\n",
|
||||
"print(liste3)\n",
|
||||
"liste3.append(\"azert\")\n",
|
||||
"print(liste3)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8a0f012c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"1. Écrire une fonction `table` qui prend en argument un nombre `a` et une longueure `n` et qui renvoie les multiples de a de 0 à a*n."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "59a55bc2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Testes\n",
|
||||
"assert table(2, 10) == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n",
|
||||
"assert table(3, 5) == [0, 3, 6, 9, 12, 15]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "69fb46d6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Fonction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "04e04b5d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "36258d27",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Pour enlever un élément, on utilise la méthode `.remove(...)`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "549a996d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[-1, 2.2, 'uio', 10, 100, 10]\n",
|
||||
"[-1, 2.2, 10, 100, 10]\n",
|
||||
"[-1, 2.2, 100, 10]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"liste3 = [-1, 2.2, \"uio\", 10, 100, 10]\n",
|
||||
"print(liste3)\n",
|
||||
"liste3.remove(\"uio\")\n",
|
||||
"print(liste3)\n",
|
||||
"liste3.remove(10)\n",
|
||||
"print(liste3)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0bc67d3c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Longueur d'une liste\n",
|
||||
"\n",
|
||||
"Pour mesurer la longueur d'une liste, on utilise la fonction `len(...)`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "9c809de2",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"5\n",
|
||||
"3\n",
|
||||
"6\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"liste1 = [1, 2, 3, 4, 5]\n",
|
||||
"print(len(liste1))\n",
|
||||
"liste2 = [\"a\", \"c\" \"uio\", \"éé\"]\n",
|
||||
"print(len(liste2))\n",
|
||||
"liste3 = [-1, 2.2, \"uio\", 10, 100, \"1000\"] \n",
|
||||
"print(len(liste3))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "88060355",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"1. Écrire une fonction `somme` qui prend en argument une liste de nombres et qui renvoie la somme des nombres"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "19510eb8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Tests\n",
|
||||
"assert somme([1, 2, 3]) == 6\n",
|
||||
"assert somme([1]) == 1\n",
|
||||
"assert somme([1, 5, 10, 0, 4]) == 20\n",
|
||||
"assert somme([1.2, 1, 1.5]) == 3.7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "38c79fed",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Fonction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f4cd9cbf",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3e7e0a3a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Écrire une fonction `moyenne` qui prend en argument une liste de nombres et qui renvoie la moyenne de ces nombres"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e83df22f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Tests\n",
|
||||
"assert moyenne([1, 2, 3]) == 2\n",
|
||||
"assert moyenne([1]) = 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "750b4e2f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Fonctions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "35efeef8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9bff74a3",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Boucle for sur une liste\n",
|
||||
"\n",
|
||||
"Il est possible de faire une boucle `for` sur les éléments d'une liste.\n",
|
||||
"\n",
|
||||
"Par exemple, la fonction `moyenne` précédement rédigée peut être réécrite de la manière suivante"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "c93f43d4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def moyenne(notes:list)->float:\n",
|
||||
" \"\"\"Calculer la moyenne des notes de la liste\"\"\"\n",
|
||||
" total = 0\n",
|
||||
" for note in notes:\n",
|
||||
" total = total + note\n",
|
||||
" return total / len(notes)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "53c180b6",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"1. Ecrire une fonction `somme` qui prend en argument une liste de nombres et qui renvoie la somme de ces nombres."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f956b1ec",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4ec924e6",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"2. Ecrire une fonction `multiplie` qui prend en argument un nombre et une liste de nombres et qui renvoie la liste des nombres multipliées par l'autre nombre."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c90251a7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#tests\n",
|
||||
"assert multiplie(2, [1, 2, 3]) == [2, 4, 6]\n",
|
||||
"assert multiplie(0, [1, 3, 6]) == [0, 0, 0]\n",
|
||||
"assert multiplie(-1, [1, 10, 100, -1]) == [-1, -10, -100, 1]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "81f3ebdf",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#Fonction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bd7c1976",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"3. Ecrire une fonction `filtre_impaire` qui prendre en argument une liste de nombres et qui renvoie une liste contenant uniquement les nombres impaires."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "b484693e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "NameError",
|
||||
"evalue": "name 'filtre_impaire' is not defined",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
||||
"Input \u001b[0;32mIn [6]\u001b[0m, in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#tests\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[43mfiltre_impaire\u001b[49m([\u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m3\u001b[39m, \u001b[38;5;241m4\u001b[39m, \u001b[38;5;241m5\u001b[39m]) \u001b[38;5;241m==\u001b[39m [\u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m3\u001b[39m, \u001b[38;5;241m5\u001b[39m]\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m filtre_impaire([\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m4\u001b[39m]) \u001b[38;5;241m==\u001b[39m []\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m filtre_impaire([]) \u001b[38;5;241m==\u001b[39m []\n",
|
||||
"\u001b[0;31mNameError\u001b[0m: name 'filtre_impaire' is not defined"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#tests\n",
|
||||
"assert filtre_impaire([1, 2, 3, 4, 5]) == [1, 3, 5]\n",
|
||||
"assert filtre_impaire([2, 4]) == []\n",
|
||||
"assert filtre_impaire([]) == []"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "c43261b1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Fonctions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fc069c83",
|
||||
"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
|
||||
}
|
174
1NSI/06_Listes_et_tuples/exercises.tex
Normal file
174
1NSI/06_Listes_et_tuples/exercises.tex
Normal file
@ -0,0 +1,174 @@
|
||||
\begin{exercise}[subtitle={QCM}, step={2}, origin={Annales}, topics={Tuples et listes}, tags={tuple, liste}]
|
||||
\begin{enumerate}
|
||||
\item Quel est le type de l'expression \texttt{f(4)} si la fonction \texttt{f} est définie par
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\inputminted[bgcolor=base3]{python}{./scripts/QCM_f.py}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
|
||||
|
||||
\begin{tasks}(4)
|
||||
\task un entier
|
||||
\task un flottant
|
||||
\task une liste
|
||||
\task un tuple
|
||||
\end{tasks}
|
||||
|
||||
\item On dispose d'une liste définie par \mintinline{python}{L = [15, 17, 12, 23]}.
|
||||
|
||||
Quelle est la valeur de L après l'instruction \mintinline{python}{L[2] = 25}
|
||||
|
||||
\begin{tasks}(2)
|
||||
\task \mintinline{python}{[15, 25, 12, 23]}
|
||||
\task \mintinline{python}{[15, 17, 25, 12, 23]}
|
||||
\task \mintinline{python}{[15, 25, 25, 23]}
|
||||
\task \mintinline{python}{[15, 17, 12, 25, 23]}
|
||||
\end{tasks}
|
||||
|
||||
\item Après l'affectation suivante :
|
||||
|
||||
\mintinline{python}{alphabet = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',] }
|
||||
|
||||
quelle est l'expression qui permet d'accéder à la lettre E?
|
||||
|
||||
\begin{tasks}(2)
|
||||
\task \mintinline{python}{alphabet.E}
|
||||
\task \mintinline{python}{alphabet['E']}
|
||||
\task \mintinline{python}{alphabet[4]}
|
||||
\task \mintinline{python}{alphabet[5]}
|
||||
\end{tasks}
|
||||
|
||||
\item On considère le script suivant:
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\inputminted[bgcolor=base3]{python}{./scripts/QCM_t.py}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
|
||||
Quelle est la valeur de t à la fin de son exécution?
|
||||
|
||||
\begin{tasks}(4)
|
||||
\task \mintinline{python}{[2, 13, 9, 2]}
|
||||
\task \mintinline{python}{[2, 8, 14, 2]}
|
||||
\task \mintinline{python}{[2, 13, 14, 2]}
|
||||
\task \mintinline{python}{[2, 13, 9, 2]}
|
||||
\end{tasks}
|
||||
|
||||
|
||||
\item On considère la fonction suivante:
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\inputminted[bgcolor=base3]{python}{./scripts/QCM_somme.py}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
|
||||
Par quelle instruction faut-il remplacer les points de suspension pour que l'appel
|
||||
|
||||
\mintinline{python}{somme([10, 11, 12, 13, 14])} renvoie 60?
|
||||
|
||||
\begin{tasks}(2)
|
||||
\task \mintinline{python}{s = tab[i]}
|
||||
\task \mintinline{python}{s = s + tab[i]}
|
||||
\task \mintinline{python}{tab[i] = tab[i] + s}
|
||||
\task \mintinline{python}{s = s + i}
|
||||
\end{tasks}
|
||||
|
||||
\item On exécute le script suivant:
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\inputminted[bgcolor=base3]{python}{./scripts/QCM_double.py}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
|
||||
Quelle est la valeur de m à la fin de son exécution?
|
||||
|
||||
\begin{tasks}(1)
|
||||
\task \mintinline{python}{[ [0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8] ] }
|
||||
\task \mintinline{python}{[ [0, 0, 0], [0, 1, 2], [0, 2, 4], [0, 3, 6], [0, 4, 8] ] }
|
||||
\task \mintinline{python}{[ [1, 1, 1], [2, 4, 6], [3, 6, 9], [4, 8, 12], [5, 10, 15] ] }
|
||||
\task \mintinline{python}{[ [1, 1, 1, 1, 1], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [4, 8, 12, 16, 20], [5, 10, 15, 20, 25] ]}
|
||||
\end{tasks}
|
||||
|
||||
\item L est une liste d'entiers. On définit la fonction suivante
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\inputminted[bgcolor=base3]{python}{./scripts/QCM_filtre.py}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
|
||||
Que calcule cette fonction?
|
||||
\begin{tasks}(1)
|
||||
\task le maximum de la liste L passée en argument
|
||||
\task le minimum de la liste L passée en argument
|
||||
\task le premier terme de la liste L passée en argument
|
||||
\task le dernier terme de la liste L passée en argument
|
||||
\end{tasks}
|
||||
|
||||
\item Quelle est la valeur de la variable r à la fin de l'exécution du script suivant?
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\inputminted[bgcolor=base3]{python}{./scripts/QCM_tuple.py}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
|
||||
\begin{tasks}(4)
|
||||
\task -9
|
||||
\task 2
|
||||
\task 3
|
||||
\task 6
|
||||
\end{tasks}
|
||||
|
||||
|
||||
\item On définit : \mintinline{python}{[10,9,8,7,6,5,4,3,2,1]}
|
||||
|
||||
Quelle est la valeur de \mintinline{python}{L[L[3]]}
|
||||
|
||||
\begin{tasks}(4)
|
||||
\task 3
|
||||
\task 4
|
||||
\task 7
|
||||
\task 8
|
||||
\end{tasks}
|
||||
|
||||
\item On considère la liste de listes suivantes
|
||||
|
||||
\begin{center}
|
||||
\begin{minipage}{0.9\linewidth}
|
||||
\inputminted[bgcolor=base3]{python}{./scripts/QCM_tictactoe.py}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
|
||||
Quelle instruction permet d'obtenir une diagonale de "X"?
|
||||
|
||||
\begin{tasks}(2)
|
||||
\task \mintinline{python}{tictactoe[3] = "X"}
|
||||
\task \mintinline{python}{tictactoe[4] = "X"}
|
||||
\task \mintinline{python}{tictactoe[1][1] = "X"}
|
||||
\task \mintinline{python}{tictactoe[2][2] = "X"}
|
||||
\end{tasks}
|
||||
|
||||
\item On définit ainsi une liste M
|
||||
|
||||
\begin{center}
|
||||
\mintinline{python}{M = [['A','B','C','D'], ['E','F','G','H'], ['I','J','K','L']] }
|
||||
\end{center}
|
||||
Quelle expression vaut la chaîne de caractères 'H'?
|
||||
|
||||
\begin{tasks}(4)
|
||||
\task \mintinline{python}{M[1][3]}
|
||||
\task \mintinline{python}{M[3][1]}
|
||||
\task \mintinline{python}{M(7)}
|
||||
\task \mintinline{python}{M(8)}
|
||||
\end{tasks}
|
||||
|
||||
|
||||
|
||||
\end{enumerate}
|
||||
\end{exercise}
|
28
1NSI/06_Listes_et_tuples/index.rst
Normal file
28
1NSI/06_Listes_et_tuples/index.rst
Normal file
@ -0,0 +1,28 @@
|
||||
Listes et tuples
|
||||
################
|
||||
|
||||
:date: 2023-01-22
|
||||
:modified: 2023-01-22
|
||||
:authors: Benjamin Bertrand
|
||||
:tags: Listes, Python
|
||||
:category: 1NSI
|
||||
:summary: Découverte et manipulation de listes et de tuples
|
||||
|
||||
|
||||
Éléments du programme
|
||||
=====================
|
||||
|
||||
Contenus
|
||||
--------
|
||||
|
||||
Capacités attendues
|
||||
-------------------
|
||||
|
||||
Commentaires
|
||||
------------
|
||||
|
||||
Progression
|
||||
===========
|
||||
|
||||
Étape 1:
|
||||
--------
|
BIN
1NSI/06_Listes_et_tuples/plan_de_travail.pdf
Normal file
BIN
1NSI/06_Listes_et_tuples/plan_de_travail.pdf
Normal file
Binary file not shown.
45
1NSI/06_Listes_et_tuples/plan_de_travail.tex
Normal file
45
1NSI/06_Listes_et_tuples/plan_de_travail.tex
Normal file
@ -0,0 +1,45 @@
|
||||
\documentclass[a4paper,12pt]{article}
|
||||
\usepackage{myXsim}
|
||||
\usepackage{minted}
|
||||
|
||||
\author{Benjamin Bertrand}
|
||||
\title{Listes et tuples - Plan de travail}
|
||||
\tribe{1NSI}
|
||||
\date{janvier 2023}
|
||||
|
||||
\pagestyle{empty}
|
||||
|
||||
\DeclareExerciseCollection{banque}
|
||||
\xsimsetup{
|
||||
}
|
||||
|
||||
|
||||
\begin{document}
|
||||
\maketitle
|
||||
|
||||
% Résumé
|
||||
|
||||
\bigskip
|
||||
|
||||
Savoir-faire de la séquence
|
||||
\begin{itemize}
|
||||
\item
|
||||
\end{itemize}
|
||||
|
||||
\bigskip
|
||||
|
||||
Ordre des étapes à respecter
|
||||
|
||||
|
||||
\section{}
|
||||
|
||||
\listsectionexercises
|
||||
|
||||
|
||||
\pagebreak
|
||||
|
||||
\input{exercises.tex}
|
||||
\printcollection{banque}
|
||||
|
||||
|
||||
\end{document}
|
6
1NSI/06_Listes_et_tuples/scripts/QCM_double.py
Normal file
6
1NSI/06_Listes_et_tuples/scripts/QCM_double.py
Normal file
@ -0,0 +1,6 @@
|
||||
m = []
|
||||
for i in range(5):
|
||||
n = []
|
||||
for j in range(3):
|
||||
n.append(i*j)
|
||||
m.append(n)
|
2
1NSI/06_Listes_et_tuples/scripts/QCM_f.py
Normal file
2
1NSI/06_Listes_et_tuples/scripts/QCM_f.py
Normal file
@ -0,0 +1,2 @@
|
||||
def f(x):
|
||||
return (x, x**2)
|
6
1NSI/06_Listes_et_tuples/scripts/QCM_filtre.py
Normal file
6
1NSI/06_Listes_et_tuples/scripts/QCM_filtre.py
Normal file
@ -0,0 +1,6 @@
|
||||
def f(L):
|
||||
m = L[0]
|
||||
for x in L:
|
||||
if x > m:
|
||||
m = x
|
||||
return m
|
5
1NSI/06_Listes_et_tuples/scripts/QCM_somme.py
Normal file
5
1NSI/06_Listes_et_tuples/scripts/QCM_somme.py
Normal file
@ -0,0 +1,5 @@
|
||||
def somme(tab):
|
||||
s = 0
|
||||
for i in range(len(tab)):
|
||||
......
|
||||
return s
|
2
1NSI/06_Listes_et_tuples/scripts/QCM_t.py
Normal file
2
1NSI/06_Listes_et_tuples/scripts/QCM_t.py
Normal file
@ -0,0 +1,2 @@
|
||||
t = [2, 8, 9, 2]
|
||||
t[2] = t[2] + 5
|
3
1NSI/06_Listes_et_tuples/scripts/QCM_tictactoe.py
Normal file
3
1NSI/06_Listes_et_tuples/scripts/QCM_tictactoe.py
Normal file
@ -0,0 +1,3 @@
|
||||
tictactoe = [['X', 'o', 'o'],
|
||||
['o', 'o', 'o'],
|
||||
['o', 'o', 'X']]
|
2
1NSI/06_Listes_et_tuples/scripts/QCM_tuple.py
Normal file
2
1NSI/06_Listes_et_tuples/scripts/QCM_tuple.py
Normal file
@ -0,0 +1,2 @@
|
||||
t = (10,6,1,12,15)
|
||||
r = t[3] - t[1]
|
28
1NSI/06_Listes_et_tuples/solutions.tex
Normal file
28
1NSI/06_Listes_et_tuples/solutions.tex
Normal file
@ -0,0 +1,28 @@
|
||||
\documentclass[a4paper,10pt]{article}
|
||||
\usepackage{myXsim}
|
||||
|
||||
\usetikzlibrary{shapes.geometric}
|
||||
|
||||
\author{Benjamin Bertrand}
|
||||
\title{Listes et tuples - Solutions}
|
||||
\tribe{1NSI}
|
||||
\date{janvier 2023}
|
||||
|
||||
\DeclareExerciseCollection{banque}
|
||||
\xsimsetup{
|
||||
exercise/print=false,
|
||||
solution/print=true,
|
||||
}
|
||||
|
||||
\pagestyle{empty}
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\input{exercises.tex}
|
||||
%\printcollection{banque}
|
||||
%\printsolutions{exercises}
|
||||
|
||||
\end{document}
|
Loading…
Reference in New Issue
Block a user