Algorithmique et programmation

📐 Mathématiques Seconde

Variables, boucles, fonctions en Python.

Introduction à Python

Algorithmique et programmation

Variables et affectation

En Python, on assigne une valeur à une variable avec = : x = 5 nom = "Alice"

Types de données

  • int : entiers (\(3\), \(-7\))
  • float : décimaux (\(3.14\), \(-2.5\))
  • str : chaînes de caractères ("Bonjour")
  • bool : booléens (True, False)

Conditions

if condition: instruction elif autre_condition: instruction else: instruction

Boucle for

for i in range(n): instruction

range(5) donne \(0, 1, 2, 3, 4\)

Boucle while

while condition: instruction

Fonctions

def ma_fonction(parametre): return resultat

Exemple : calcul d'une moyenne

def moyenne(liste): return sum(liste) / len(liste)

Aucun exercice disponible pour ce chapitre.

Aucun QCM disponible pour ce chapitre.

Aucun contrôle disponible pour ce chapitre.