-
Notifications
You must be signed in to change notification settings - Fork 0
/
TP1_devine.py
52 lines (50 loc) · 1.41 KB
/
TP1_devine.py
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
import random as rnd
def joueurA(n):
perdu=True
k=rnd.randint(1,n)
score=0
while perdu:
score=score+1
prop=int(input('Votre proposition?'))
perdu=not((prop==k))
if prop<k:
print('Plus grand')
else:
if prop>k:
print('Plus petit')
print(f"Vous avez trouvé le nombre {k} en {score} essais")
if 2**score>n:
print("Pas top!!!")
else:
print("Pas mal :-/")
return score
def joueurB(n):
print(f"Choisissez un nombre de 1 à {n}, je vais le deviner!")
print("Lorsque que je vous fais une proposition, répondez-moi Plus, Moins ou Gagné on y va?")
score=0
a=1
b=n
k=(a+b)//2
print(k)
test=input('Alors?')
encore=not((test=='Gagné')or(test=='gagné'))
while encore:
score=score+1
if (test=='Plus' or test=='plus'):
a=k
k=(a+b)//2
else:
if ((test=='moins')or(test=='Moins')):
b=k
k=(a+b)//2
else:
print('Merci de répondre')
print(f"Je propose {k}")
test=input('Alors?')
encore=not((test=='Gagné')or(test=='gagné'))
print(f"J'ai gagné en {score} coups!!!")
if 2**score>n:
print('Peut mieux faire')
else:
print("Et j'ai la grande classe...")
return score