2018年1月9日 星期二

Python: Convert seconds to day, hour, minutes and seconds

Python: Convert seconds to day, hour, minutes and seconds

Python Basic: Exercise-65 with Solution

Write a Python program to convert seconds to day, hour, minutes and seconds.
Sample Solution:-
time = float(input("Input time in seconds: "))
day = time // (24 * 3600)
time = time % (24 * 3600)
hour = time // 3600
time %= 3600
minutes = time // 60
time %= 60
seconds = time
print("d:h:m:s-> %d:%d:%d:%d" % (day, hour, minutes, seconds))

========== RESTART: F:/Python_APSC/py-ex-basic-65.py ===========
Input time in seconds: 20000
d:h:m:s-> 0:5:33:20
>>> 
=========== RESTART: F:/Python_APSC/py-ex-basic-65.py ==========
Input time in seconds: 36005
d:h:m:s-> 0:10:0:5
>>> 

沒有留言:

張貼留言

OPEN DATA AQI 空氣品質監測網 + NODE-RED

OPEN DATA AQI 空氣品質監測網 + NODE-RED  首頁 - 空氣品質監測網  https://airtw.moenv.gov.tw/ https://data.gov.tw/datasets/search?p=1&size=10&s=_score...