I am trying to write a function in python whereby I can input a start time and end time and it will return the total hours.
Currently I have been able to write a function where I input for example ('07:30:00', '12:00:00') and it returns 4.5
I want to be able to import a list though. For example,
('07:30:00, 08:30:00', '12:00:00, 12:00:00') and have it return 4.5 , 3.5 etc....
How do I alter my code so I can do this?
Thanks
I have been messing around for hours but am very new to python so do not know how to progress from here
def compute_opening_duration(opening_time, closing_time):
while True:
try:
FORMAT = '%H:%M:%S'
tdelta = datetime.strptime(closing_time, FORMAT) - datetime.strptime(opening_time, FORMAT)
tdelta_s = tdelta.total_seconds()
tdelta_m = tdelta_s/60
tdelta_h = tdelta_m/60
print(tdelta_h)
break
except ValueError:
print('-1')
break