blob: 060f8957436ac156d0305ea7b50c7efa5fca18e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()
|