Agradecemos tu apoyo para difundir nuestros enunciados con relación a las ciencias de la computación.
Ejemplo: juego de adivinanzas python
# updated versionimport random
# for instructions so that the user understandsdefinstructions():print("Welcome to the guessing game you will have 3 tries to pick a number 1-10")print("Good luck btw it's all random")
instructions()# guess limit so the user can't guess too much.
guess_limit =1# The random guess
number = random.randint(1,10)# What users can type and see.
user =int(input("What is the number?: "))# The while loop so it can go on.while user != number:if user > number:print("Lower")elif user < number:print("Higher")
user =int(input("What is the number?: "))
guess_limit +=1if guess_limit ==3:print("------------------------------------------------------")print("You ran out of guess ;( the answer was", number,"<--")print("------------------------------------------------------")breakelse:print("You guessed it right! The number is", number,"and it only took you ", guess_limit,"tries")
Si para ti ha resultado útil nuestro post, sería de mucha ayuda si lo compartieras con más juniors de este modo nos ayudas a extender nuestro contenido.
¡Haz clic para puntuar esta entrada!
(Votos: 2 Promedio: 4)