Tell us what’s happening:
im passing every test except the test where inputing 0:00 as the duration should return the initial time. i dont know where i went wrong or if it has to be something specific
Your code so far
def add_time(start, duration, days = False):
weekdays = {'Monday':0, 'Tuesday':1, 'Wednesday':2, 'Thursday':3, 'Friday':4 ,'Saturday':5, 'Sunday':6}
weekdaysarray = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday' ,'Saturday', 'Sunday']
[r, ap] = start.split(' ')
[shours, sminutes] = r.split(':')
[dhours, dminutes] = duration.split(':')
total_hours = int(shours) + int(dhours)
total_minutes = int(sminutes) + int(dminutes)
aod = int(dhours)//24
aps = 0
if total_minutes > 60:
total_minutes -= 60
total_hours +=1
if total_minutes < 10:
total_minutes = '0'+str(total_minutes)
if total_hours >= 12:
t, l = divmod(total_hours, 12)
total_hours = l if l else int(total_hours/t)
if t > 0 and t%2 != 0:
if ap == 'PM':
ap = 'AM'
aod += 1
else:
ap = 'PM'
new_time = str(total_hours) + ':'
new_time += str(total_minutes) + ' ' + ap
if days:
days = days.lower()
days = days[0].upper() + days[1:]
index = int((weekdays[days]) + aod) % 7
new_day = weekdaysarray[index]
new_time += ', ' + new_day
if aod == 0:
return new_time
elif aod == 1:
return new_time + ' (next day)'
elif aod > 1:
return new_time + ' (' + str(aod) + ' days later)'
#print(add_time('11:30 AM', '2:32','Monday'))
#print(add_time('8:16 PM', '00:00', 'tuesday'))
#print(add_time('11:43 PM', '00:20'))
#print(add_time('3:30 PM', '2:12'))
#print(add_time('10:10 PM', '03:30'))
#print(add_time('11:59 PM', '0:00'))
#print(add_time('3:30 PM', '2:12', 'Monday'))
print(add_time('8:16 PM', '0:00', 'tuesday'))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Challenge Information:
Build a Time Calculator Project - Build a Time Calculator Project