Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- Crear una función que reciba un número como argumento, ese número
- representará los segundos que se quieren convertir a horas, minutos y
- segundos.
- Por ejemplo, conversion(3600) retornaría el texto
- “01:00:00” , en cambio si recibe 1000, devolverá
- “00:16:40”
- No se puede usar ninguna función built-in, ni
- tampoco ningún módulo que haga la conversión.
- """
- def conversion(seg):
- minutos = 0
- horas = seg // 3600
- segundos = seg % 3600
- if segundos >= 60:
- minutos = segundos // 60
- segundos = segundos % 60
- if horas < 10:
- horas = f"0{horas}"
- if minutos < 10:
- minutos = f"0{minutos}"
- if segundos < 10:
- segundos = f"0{segundos}"
- return f"{horas}:{minutos}:{segundos}"
- def ingresar():
- while True:
- try:
- tiempo = int(input("Ingrese el tiempo en segundos: "))
- except ValueError:
- print("Debe ingresar un nro entero de segundos")
- else:
- if tiempo >= 0:
- return tiempo
- else:
- print("El tiempo debe ser no negativo")
- t = ingresar()
- print(conversion(t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement