Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- correcto = False
- while not correcto: # Equivalente a while correcto != True: . Si la variable a testear fuese incorrecto = True, y se quisiera salir si fuese True, se escribiría while incorrecto: .
- numero = int(input("Introduce un número del 1 al 10: "))
- if numero < 1 and numero > 10:
- print("Has introducido un número fuera del rango (del 1 al 10") # No se tiene que repetir la instrucción otra vez, el programa vuelve al principio del bucle solo.
- elif numero ==5:
- print("Correcto!")
- correcto = True # Hecho esto se sale del bucle, dejamos de tener que indentar nada si ya hemos terminado.
- else: # Si estamos en rango pero no hemos introducido el número bien. Una vez más, no se tiene que repetir nada.
- print("No, prueba otra vez.")
- print("Gracias por jugar!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement