Tell us what’s happening:
Hello there, i have been trying to create the Time Calculator… but i can’t seem to visualize this problem! Maybe i’m not keeping it simple, but i’m blocked with adding the next day thing and calculating how many days have passed.
Your code so far
def add_time(start, duration):
time_date = start.split(' ')
time = time_date[0].split(':')
time_passed = duration.split(':')
hour = time[0]
minute = time[1]
part_of_day = time_date[1]
end = [int(hour), int(minute), part_of_day]
if end[0] + int(time_passed[0])>= 12:
end[0] += int(time_passed[0]) - 12
end[2] = 'PM'
else:
end[0] += int(time_passed[0])
if end[1] + int(time_passed[1]) >= 60:
end[1] += int(time_passed[1]) - 60
end[0] += 1
else:
end[1] += int(time_passed[1])
if end[0] == 12:
end[2] = 'PM'
if end[1] < 10:
new_time = f'{end[0]}:0{end[1]} {end[2]}'
else:
new_time = f'{end[0]}:{end[1]} {end[2]}'
print(new_time)
return new_time
add_time('11:55 AM', '3:12')
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0
Challenge Information:
Build a Time Calculator Project - Build a Time Calculator Project