Advertisement
Guest User

adivina

a guest
Mar 25th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. correcto = False
  2. 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: .
  3. numero = int(input("Introduce un número del 1 al 10: "))
  4. if numero < 1 and numero > 10:
  5. 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.
  6. elif numero ==5:
  7. print("Correcto!")
  8. correcto = True # Hecho esto se sale del bucle, dejamos de tener que indentar nada si ya hemos terminado.
  9. else: # Si estamos en rango pero no hemos introducido el número bien. Una vez más, no se tiene que repetir nada.
  10. print("No, prueba otra vez.")
  11. print("Gracias por jugar!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement