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
>>> 

沒有留言:

張貼留言

MQTT WS HMI 與 Wokwi ESP32 連線的資訊透過HiveMQ

MQTT WS HMI 與 Wokwi ESP32 連線的資訊透過HiveMQ     https://console.hivemq.cloud/clusters 當您進入 HiveMQ Cloud Console 的 Clusters 頁面時,您的目標是取得能讓 MQTT W...