Convert Asciidoc to markdown

Converted asciidoc to markdown using ai.
This commit is contained in:
2025-07-06 22:07:31 +02:00
parent ebe0844882
commit bea28eca14
26 changed files with 352 additions and 388 deletions

View File

@ -0,0 +1,36 @@
# Exercices sur les exceptions
## Exercice 1
- Écrivez un bloc `try/except`
- Dans le bloc `try`, provoquez une division par zéro (`ZeroDivisionError`)
- Dans le bloc `except`, affichez "Division impossible !"
## Exercice A1
- Générez un nombre entier aléatoire entre 0 et 1 :
```python
from random import randint
number = randint(0, 1)
```
- Écrivez un bloc `try/except`
- Dans le bloc `try` :
- Si `number` vaut `0`, afficher `[1, 2, 3][4]` (`IndexError`)
- Si `number` vaut `1`, afficher `{}[0]` (`KeyError`)
- Écrire un bloc `except` pour `IndexError`, qui affiche "Erreur d'index"
- Écrire un bloc `except` pour `KeyError`, qui affiche "Erreur de clé"
## Exercice A2 (variante)
- Reprenez une copie de l'exercice 1
- Mais cette fois, ayez un seul bloc `except` qui gère à la fois `IndexError` et `KeyError`, et qui affiche "Erreur d'accès".
## Exercice A3
- Écrivez un bloc `try/except`
- Provoquez une erreur dans le bloc `try` (pas une erreur de syntaxe !)
- Écrivez un bloc `except` qui ne gère pas la bonne erreur (ex. `IOError`)
- Écrivez un bloc `finally` qui affiche du texte
- Exécutez votre code et voyez que le bloc `finally` est bien honoré.