Paso 14: Número programa de adivinar
import random number =int(raw_input("Guess a number (between 1 and 100):")) # initially ask the user for a number randNumber = random.randint(1,100) # create a random numberwhile number != randNumber: # if the user guessed correctly on first try this whole loop is skipped number =int(raw_input("You didn't guess right, guess again:")) # re-store a user-input number, it will get checked automatically at the end of the loopprint"You guessed correctly!"# the only way you can reach this line of code is if the user guessed correctly.
OK, esto es bastante difícil. Así que ¿por qué no hace la exhibición si adivinaron a alta o baja?
Una vez más, la solución puede variar:
import random number =int(raw_input("Guess a number (between 1 and 100):")) randNumber = random.randint(1,100) while number != randNumber: if number > randNumber: print"You guessed to high"else: print"You guessed to low" number =int(raw_input("Guess again:")) print"You guessed correctly!"
*.Step-cuerpo > pre, pre {color de fondo: rgb(39,40,34), color: rgb(248,248,242); padding: 5.0px;}