teslariu

biblio time random

Nov 25th, 2022
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # implementar un contador en forma regresiva que simule la explosion
  5. # de una bomba:
  6. # Ej:
  7. # >>> Ingrese un tiempo: 3
  8. # >>> 3
  9. # >>> 2
  10. # >>> 1
  11. # >>> BOOOMMM
  12.  
  13. # usar time.sleep()
  14.  
  15. import time
  16.  
  17. def ingresar():
  18.     while True:
  19.         tiempo = input("Ingrese el tiempo: ")
  20.         if tiempo.isdecimal() and int(tiempo) != 0:
  21.             return int(tiempo)
  22.         print("Error, debe ingresar un numero entero mayor a cero")
  23.  
  24.  
  25. def explotar(tiempo):
  26.     for t in range(tiempo,0,-1):
  27.         print(t)
  28.         time.sleep(1)
  29.     print("BOOOM")
  30.    
  31.    
  32. tiempo = ingresar()
  33. explotar(tiempo)
  34.  
  35. ## Script que pide adivinar un numero entre 1 y 100. Tiene 5 oportunidades
  36. import random
  37.  
  38. numero = random.randint(1,100)
  39. acertado = False
  40.  
  41. print("Adivine un numero entre 1 y 100. Tiene 5 oportunidades")
  42.  
  43. for i in range(5):
  44.     print(f"{i+1}ยบ oportunidad")
  45.     n = int(input("Ingrese un nro: "))
  46.     if n == numero:
  47.         print("Ha acertado. Felicitaciones...")
  48.         acertado = True
  49.         break
  50.     elif n > numero:
  51.         print("Elija un numero menor...")
  52.    
  53.     else:
  54.         print("Elija un numero mayor...")
  55.        
  56. if not acertado:
  57.     print("Ha perdido...")
  58.     print(f"El nro buscado era {numero}")
  59.  
Advertisement
Add Comment
Please, Sign In to add comment