Created
May 2, 2022 16:57
-
-
Save macndesign/05c42a81bcbb042e2a1b160da2b113ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_hours(hours): | |
total_secs = 0 | |
for tm in hours: | |
time_parts = [int(s) for s in tm.split(':')] | |
total_secs += (time_parts[0] * 60 + time_parts[1]) * 60 | |
total_secs, _ = divmod(total_secs, 60) | |
hr, min = divmod(total_secs, 60) | |
return "%d:%02d" % (hr, min) | |
print('Press "e" to exit') | |
time_list = [] | |
while True: | |
time = input('Enter time (HH:MM): ') | |
if time == 'e': | |
break | |
time_list.append(time) | |
print(sum_hours(time_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment