forked from digitalheadhunt/EstudoPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_readable.py
53 lines (43 loc) · 1.23 KB
/
make_readable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
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)
:param seconds:
:return:
"""
"""
def make_readable(seconds: int) -> str:
hours = seconds // (60 * 60)
minutes = (seconds - (hours * 60 * 60)) // 60
seconds = seconds - (hours * 60 * 60) - (minutes * 60)
if hours == 0:
hours_str: str = '00'
else:
if len(str(hours)) > 1:
hours_str = str(hours)
else:
hours_str = '0' + str(hours)
if minutes == 0:
minutes_str: str = '00'
else:
if len(str(minutes)) > 1:
minutes_str = str(minutes)
else:
minutes_str = '0' + str(minutes)
if seconds == 0:
seconds_str: str = '00'
else:
if len(str(seconds)) > 1:
seconds_str = str(seconds)
else:
seconds_str = '0' + str(seconds)
result: str = '{}:{}:{}'.format(
hours_str,
minutes_str,
seconds_str
)
return result"""