Advertisement
Sergio_Istea

while 1.py

Oct 23rd, 2023
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. #!/bin/python
  2.  
  3. # Se importa el modulo 'random'
  4. import random
  5.  
  6. # al ejecutarse el programa 'numero_secreto' va a tomar un valor
  7. # aleatorio entre 1 y 10.
  8. numero_secreto = random.randint(1, 10)
  9.  
  10. contador = 1
  11.  
  12. while True:
  13.    
  14.     # se pide que se ingrese un numero.
  15.    
  16.     adivinanza = int(input("Adivina el número secreto (entre 1 y 10): "))
  17.    
  18.     # Sentencia if dentro del while
  19.    
  20.     if adivinanza == numero_secreto:
  21.    
  22.         print("¡Adivinaste!")
  23.    
  24.     else:
  25.    
  26.         print("Intenta de nuevo.")
  27.  
  28.         if contador == 4:
  29.  
  30.             print("se termino el juego")
  31.             break
  32.         else:
  33.             contador += 1
  34.  
  35.  
  36.  
  37. print("fin del programa.")
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement