將秒數轉換為等量的時、分、秒


編寫一個程式,該程式將接受由使用者輸入的數秒,並輸出相等數量的小時、分鐘和秒。

# Seconds Conversion

n = int(input("Enter the number of seconds: "))
s = n
m = s // 60
s = s % 60
h = m // 60
m = m % 60
print ("%d seconds = %d hour(s), %d minute(s), %d second(s)." % (n,h,m,s))

在此示例中,我們輸入3920 (秒),結果如下
Enter the number of seconds: 3920
3920 seconds = 1 hour(s), 5 minute(s), 20 second(s).