aapssfc/src/devine_ordi_0.py

48 lines
875 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#encoding: utf-8
import random
min=0
max=10
print("Pense à un nombre entre",min,"et",max)
essais = 4
def deviner(nb_min,nb_max):
if nb_min == nb_max or nb_min > nb_max:
print("Tu as triché !")
hasard = random.randint(nb_min,nb_max)
return hasard
def repondu( reponse ):
if reponse == 0:
min = min + 1
return False
elif reponse == 1:
max = max - 1
return False
elif reponse == 2:
print("Enfin !")
return True
else:
print("Tu dois répondre par 1, 2 ou 3 !")
return False
while essais > 0:
devine = deviner(min,max)
print("Je pense au nombre",devine,", est-il:")
print("0: trop petit ?")
print("1: trop grand ?")
print("2: le bon numéro ?")
reponse = int( input() )
trouve = repondu( reponse )
if trouve == True:
break