diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /ero1/src/demo/ask_variable.py | |
Diffstat (limited to 'ero1/src/demo/ask_variable.py')
| -rw-r--r-- | ero1/src/demo/ask_variable.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ero1/src/demo/ask_variable.py b/ero1/src/demo/ask_variable.py new file mode 100644 index 0000000..f2f9330 --- /dev/null +++ b/ero1/src/demo/ask_variable.py @@ -0,0 +1,26 @@ +from src.demo.print_demo import print_demo +import os + +def ask_variable(question, answers): + """ + Pose une question avec des réponses multiples et attend une réponse de l'utilisateur. + Parameters: + question : La question à afficher + answers : Liste de tuples contenant (réponse, valeur) + """ + print("") + print_demo(f"{question}") + for i, (answer_text, _) in enumerate(answers, 1): + print_demo(f"{i}. {answer_text}", 1) + + while True: + try: + choice = input("\n⟩ Entrez le numéro de votre choix ou 'stop' pour arrêter : ") + if choice == "stop": + raise KeyboardInterrupt + choice = int(choice) + if 1 <= choice <= len(answers): + return answers[choice - 1][1] + print_demo(f"Insérez un nombre entre 1 et {len(answers)}", 1) + except ValueError: + print_demo(f"Insérez un nombre entre 1 et {len(answers)}", 1) |
