summaryrefslogtreecommitdiff
path: root/nbmystere.py
diff options
context:
space:
mode:
authorjerome <jerome@xlinfo.fr>2024-04-03 18:25:22 +0200
committerjerome <jerome@xlinfo.fr>2024-04-03 18:25:22 +0200
commitc2277d66411317a3ed6f8e1fac6f000387d3b7c5 (patch)
tree87da13d29ebfc7c415e8803fce04c4bb4509ead4 /nbmystere.py
parent8972fd920044de719811fd71d50b98d2e2377e7b (diff)
downloadjeux-c2277d66411317a3ed6f8e1fac6f000387d3b7c5.tar.gz
jeux-c2277d66411317a3ed6f8e1fac6f000387d3b7c5.zip
ajout de nbmystere
Diffstat (limited to 'nbmystere.py')
-rw-r--r--nbmystere.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/nbmystere.py b/nbmystere.py
new file mode 100644
index 0000000..060f895
--- /dev/null
+++ b/nbmystere.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()
+
+