练习题 将输入的秒数转换为时间格式

原题

Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS)

  • HH = hours, padded to 2 digits, range: 00 - 99
  • MM = minutes, padded to 2 digits, range: 00 - 59
  • SS = seconds, padded to 2 digits, range: 00 - 59

The maximum time never exceeds 359999 (99:59:59)

You can find some examples in the test fixtures.


我的解法

def make_readable(seconds):
    h = seconds // 3600
    seconds -= h * 3600
    m = seconds // 60
    seconds -= m * 60
    s = seconds
    return '%02d:%02d:%02d' % (h,m,s)

我觉得难点不多,但这道题在网站上难度系数还不低,费解...


你可能感兴趣的:(python)