Skip to content

Instantly share code, notes, and snippets.

@macndesign
Created May 2, 2022 16:57
Show Gist options
  • Save macndesign/05c42a81bcbb042e2a1b160da2b113ee to your computer and use it in GitHub Desktop.
Save macndesign/05c42a81bcbb042e2a1b160da2b113ee to your computer and use it in GitHub Desktop.
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