| Erreur | Ce qu'elle signifie | Exemple de cause |
|---|---|---|
SyntaxError | Python ne comprend pas la syntaxe. | oubli de : |
IndentationError | Le retrait d'un bloc est incorrect. | ligne sous un if non indentée |
NameError | Nom inconnu. | print(totla) au lieu de total |
TypeError | Types incompatibles. | "5" + 2 |
ValueError | Valeur impossible à convertir. | int("abc") |
IndexError | Indice hors de la liste. | [10,20][5] |
ZeroDivisionError | Division par zéro. | 10 / 0 |
# Affectation
age = 20
# Comparaison
if age == 20:
print("20 ans")
# Mauvais si on veut calculer :
age = input("Age : ")
# print(age + 1) -> TypeError
# Correct :
age = int(input("Age : "))
print(age + 1)
i = 3
total = 42
print("DEBUG i =", i)
print("DEBUG total =", total)
Ajoutez temporairement des affichages pour suivre les valeurs. Retirez-les quand le programme fonctionne.