-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem2.py
More file actions
29 lines (22 loc) · 797 Bytes
/
Copy pathproblem2.py
File metadata and controls
29 lines (22 loc) · 797 Bytes
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
"""
A program to convert a number to hours, minutes,
and seconds in a 24-hour clock format.
"""
#index will add s if plural
def singlePlural(num):
if num == 1:
return 0
else:
return 1
suffix = ["", "s"]
#prompt the user to enter a number
time = int(input("Enter a number from 1 to 86400: "))
#conversion to hours, minutes, seconds
hours = time // 3600
output_hours = "hour{}".format(suffix[singlePlural(hours)])
minutes = (time % 3600) // 60
output_minutes = "minute{}".format(suffix[singlePlural(minutes)])
seconds = (time % 3600) % 60
output_seconds = "second{}".format(suffix[ singlePlural(seconds)])
#print conversion in hours, minutes, seconds
print("{} {}, {} {}, and {} {}".format(hours, output_hours, minutes, output_minutes, seconds, output_seconds))