Advertisement
teslariu

bomba.py

Sep 5th, 2023
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # hacer una funcion que simule un contador. Se debe ingresar un tiempo
  5. # y se debe mostrar la cuenta regresiva
  6. # Ej:
  7. # >>> Ingrese el tiempo: 3
  8. # >>> 3
  9. # >>> 2
  10. # >>> 1
  11. # >>> ¡BOOOM!
  12.  
  13.  
  14. # El tiempo se puede pedir en la funcion cuenta regresiva o pasárselo
  15. # como argumento
  16. #def cuenta_regresiva():
  17. #   pass
  18. import time
  19.  
  20. def ingresar():
  21.     while True:
  22.         tiempo = input("Ingrese el tiempo: ")
  23.         if tiempo.isdecimal() and int(tiempo):
  24.             return int(tiempo)
  25.         else:
  26.             print("Error: ingrese un tiempo válido")
  27.  
  28.  
  29.  
  30. def cuenta_regresiva(tiempo):
  31.     print('The Bomb has been planted') 
  32.        
  33.     for i in range(tiempo, 0, -1):
  34.         print(f"Tiempo restante: {i} segundos")
  35.         time.sleep(1)
  36.     print("¡BOOOM, TERRORIST WIN!")
  37.  
  38.  
  39. if __name__ == '__main__':
  40.     tiempo = ingresar()    
  41.     cuenta_regresiva(tiempo)
  42.  
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement