summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjerome <jerome@xlinfo.fr>2024-04-03 18:27:47 +0200
committerjerome <jerome@xlinfo.fr>2024-04-03 18:27:47 +0200
commit7c4b7afff1223f80cbfa9d201907231915835906 (patch)
tree99aa3209d0f9dc6419c19b0d80049f6da753ce17
parentc2277d66411317a3ed6f8e1fac6f000387d3b7c5 (diff)
downloadjeux-7c4b7afff1223f80cbfa9d201907231915835906.tar.gz
jeux-7c4b7afff1223f80cbfa9d201907231915835906.zip
MAJ
-rwxr-xr-x[-rw-r--r--]nbmystere.py56
1 files changed, 19 insertions, 37 deletions
diff --git a/nbmystere.py b/nbmystere.py
index 060f895..cab6559 100644..100755
--- a/nbmystere.py
+++ b/nbmystere.py
@@ -1,52 +1,34 @@
#!/usr/bin/env python3
-"""Le nombre mystère"""
-
-import os
+"""module du jeu du nombre mystère"""
+import sys
import random
-import cowsay
-def jouer(limite):
- """ touver un nombre entre 1 et une limite donnée en argument"""
+
+def jouer(limite=100):
+ """fonction jouer avec en argument la limite supérieure de l'intervalle"""
nb = 0
cpteur = 0
secret = random.randrange(1, limite)
- # print(secret)
+ # print(f"debug : {secret = }")
while nb != secret:
+ cpteur = cpteur + 1
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')
+ nb = int(input(f"Trouvez le nombre secret entre 1 et {limite} : "))
except ValueError:
+ print("On a dit un nombre !")
continue
- os.system("clear")
- cowsay.cow(f"Gagné en {cpteur} coups !")
+ if nb > secret:
+ print("Trop grand")
+ elif nb < secret:
+ print("Trop petit")
-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(" -------------------------- ")
+ print(f"Gagné en {cpteur} tentatives")
- 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()
-
-
+ try:
+ limite = int(sys.argv[1])
+ jouer(limite)
+ except IndexError:
+ print(f"{sys.argv[0] } nécessite une limite en argument")