
ULUMINE · Mathématiques · Seconde
Algorithmique et programmation en Python
Un programme Python = des variables, des tests, des boucles et des fonctions.
Syntaxe
- Affectation : x = x + 1
- Test : if … : / elif … : / else :
- Fonction : def f(x): … return …
Boucles
- for k in range(a, b) : de a à b − 1
- while condition : tant que c’est vrai
- // quotient, % reste
Hasard
- random() : flottant dans [0 ; 1[
- randint(a, b) : entier de a à b inclus
Pièges à éviter
- Confondre = (affectation) et == (test).
- Oublier que range(1, 5) s’arrête à 4.