Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # hacer un script que simule un contador en forma regresiva empezando
- # desde un valor ingresado por consola
- # ej:
- # >>> Ingrese un número entero mayor a cero: 5
- # >>> 5
- # >>> 4
- # >>> 3
- # >>> 2
- # >>> 1
- # >>> ¡BOOOMMM!
- # AYUDA: biblioteca time, función sleep ---> time.sleep
- #
- # TICKET 1: validar que el tiempo ingresado sea válido
- #
- # TICKET 2: implementar funciones para mejorar la modularidad y
- # reimplementación del uso
- import time
- def ingresar_entero():
- while True:
- tiempo = input("Ingrese un número entero mayor a cero: ")
- if tiempo.isdecimal():
- return int(tiempo)
- print(f"Error: {tiempo} no es un entero mayor a cero")
- def cuenta_regresiva(n):
- for i in range(n,0,-1):
- time.sleep(1)
- print(i)
- return "¡BOOOMMM!"
- numero = ingresar_entero()
- print(cuenta_regresiva(numero)) # imprime el return de la función
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement