[5 kyu] Human Readable Time
Question
Sample Tests
My Answer (accepted)
def make_readable(seconds):
if seconds >= 0 and seconds < 60:
one_part = "00:00:" + str(seconds).zfill(2)
print(one_part)
return one_part
if seconds >= 60 and seconds < 60*60:
first_part = seconds // 60
second_part = seconds % 60
two_part = "00:" + str(first_part).zfill(2) + ":" + str(second_part).zfill(2)
print(two_part)
return two_part
if seconds >= 60*60 and seconds < 60*60*100:
first_part = seconds // (60*60)
second_part = seconds % (60*60) // 60
third_part = seconds % (60*60) % 60
three_part = str(first_part).zfill(2) + ":" + str(second_part).zfill(2) + ":" + str(third_part).zfill(2)
print(three_part)
return three_part
Suggested Answer
def make_readable(s):
return '{:02}:{:02}:{:02}'.format(s // 3600, s // 60 % 60, s % 60)