python——秒(s)的轉換

 1 #!/usr/bin/env python3
 2 # -*- coding: utf-8 -*-
 3 #n=0 --> 0d0h0m0s
 4 #n=63 --> 0d0h1m3s
 5 #n=1235 --> 0d0h20m35s
 6 n = int(input('n = '))  7 if n < 0:  8  exit()  9 S = 1
10 M = 60 * S 11 H = 60 * M 12 D = 24 * H 13 d = n // D 14 n = n % D 15 h = n // H 16 n = n % H 17 m = n // M 18 n = n % M 19 s = n // S 20 print('%dd%dh%dm%ds' %(d, h, m, s))

如:
[root@lpc 04-3-經過秒求時間]# python3 04-4.py
n = 1600
0d0h26m40s
相關文章
相關標籤/搜索