summaryrefslogtreecommitdiff
path: root/jeu.py
diff options
context:
space:
mode:
authorjerome <jerome@xlinfo.fr>2023-06-01 15:50:09 +0200
committerjerome <jerome@xlinfo.fr>2023-06-01 15:50:09 +0200
commit095144f26c0c9c417589fa0be5f6732f7348cae4 (patch)
tree7d1c30708566727c26684ad504fc3926d8751bf3 /jeu.py
downloadjeux-095144f26c0c9c417589fa0be5f6732f7348cae4.tar.gz
jeux-095144f26c0c9c417589fa0be5f6732f7348cae4.zip
commit initial
Diffstat (limited to 'jeu.py')
-rw-r--r--jeu.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/jeu.py b/jeu.py
new file mode 100644
index 0000000..060f895
--- /dev/null
+++ b/jeu.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+"""Le nombre mystère"""
+
+import os
+import random
+import cowsay
+
+def jouer(limite):
+ """ touver un nombre entre 1 et une limite donnée en argument"""
+ nb = 0
+ cpteur = 0
+ secret = random.randrange(1, limite)
+ # print(secret)
+
+ while nb != secret:
+ try:
+ cpteur += 1
+ nb = int(input(f'Entrez un nombre entre 1 et {limite} : '))
+ if nb > secret:
+ print('Trop grand')
+ elif nb < secret:
+ print('Trop petit')
+ except ValueError:
+ continue
+ os.system("clear")
+ cowsay.cow(f"Gagné en {cpteur} coups !")
+
+def main():
+ """ lance le jeu en proposant différents niveaux"""
+ os.system("clear")
+ menu = {1:'débutant',2:'intermédiaire', 3:'expert'}
+ rep = 0
+ while rep != "q" :
+ print(" -------------------------- ")
+ print("< Jeu du nombre mystérieux >")
+ print(" -------------------------- ")
+
+ for niveau in menu.keys():
+ print(niveau, menu[niveau])
+
+ rep = input("Choisissez votre niveau (q pour quitter) : ")
+ try:
+ if int(rep) in menu.keys():
+ jouer(10**int(rep))
+ except ValueError:
+ continue
+ print("Bye")
+
+if __name__ == "__main__":
+ main()
+
+