Conception d'un jeu de hasard en Python (ti wobo, lawoulèt)
Pour le dernier essai, le programme devrait aider un peu l'utilisateur en lui indiquant si le dernier nombre qu'il a choisi est inférieur ou supérieur au nombre correct.
import random
if __name__ == '__main__':
nombre = random.randint(1, 3)
essais = 3
choix=int(input("Entrez un nombre entre 1 à 3"))
while choix != nombre:
essais -= 1
if essais > 0:
if essais == 1:
if nombre > choix:
print("votre choix est inférieur au nombre choisi")
else:
print("votre choix est supérieur au nombre choisi")
choix = int(input("Mauvais choix, Entrez un nombre entre 1 à 3"))
else:
print("Désolé vous avez perdu! le nombre est : "+str(nombre))
break
if choix == nombre:
print("bravo, vous avez gagné")
Exercice final
https://codingclubhaiti.com/archive/programmation-fondamentale--exercice-final/3/23
Python Challenge
https://codingclubhaiti.com/archive/python-challenge/1/24