# Time calculator 2 failures 1 error(HELP)

Hi i made the code but when i run it has an error , and 2 failures
My code:
def add_time(tim,dur,day_in = ’ ’ ):
days = [“monday”,“tuesday”,“wednesday”,“thursday”,“friday”,“saturday”,“sunday”]
day = 0

``````time,am_pm = tim.split()

hour,mi=time.split(':')

if am_pm == 'PM':
hours12 = 12 + int(hour)
else :
hours12 = hour

extra_hours,extra_mi = dur.split(':')

new_mi = int(mi) + int(extra_mi)
new_hours = int(hours12) + int(extra_hours)

if new_mi >= 60 :
new_hours = new_hours + new_mi//60
new_mi = new_mi%60
if new_mi < 10 :
new_mi = '0'+str(new_mi)

if new_hours > 24:
day = new_hours // 24
#if new_hours % 24 == 0:
#    new_hours // 24
#else :
new_hours = new_hours % 24

if new_hours >= 12 :
if new_hours > 12 :
new_hours = new_hours - 12
am_pm = 'PM'
else :

am_pm = 'AM'

re = (str(new_hours)+":"+str(new_mi)+' '+am_pm)

if day_in != ' ':
days_after = days.index(day_in.casefold())
if day > 0 :
while days_after + day> len(days):
days_after -= 7
#if days_after + day < len(days):
pos = days_after + day

re = (str(new_hours)+":"+str(new_mi)+' '+am_pm+', '+days[pos].capitalize())
else :
re = (str(new_hours)+":"+str(new_mi)+' '+am_pm+', '+days[days_after].capitalize())

if day == 0 :
if day_in == ' ':
re = (str(new_hours)+":"+str(new_mi)+' '+am_pm)
elif day == 1 :
re = re +' (next day)'
else:
re = re+' ('+str(day)+' days later)'
return re
``````

(https://repl.it/@DimosRetsidis/boilerplate-time-calculator-1?v=1)
User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36`.

Challenge: Time Calculator

1 Like

Hey!

For your 2 failures, I think this come from a misconception about the AM/PM system, as I had. Starting hours in AM/PM are 12:xx and not 00:xx.

``````AssertionError: '0:04 AM, Friday (2 days later)' != '12:04 AM, Friday (2 days later)'
- 0:04 AM, Friday (2 days later)
? ^
+ 12:04 AM, Friday (2 days later)
? ^^
``````

In this error, the “-” line is what you output, the “+” line is what you want. So for passing theses you’ll need to translate the hour 0 to 12.

For this error →

``````  File "/home/runner/6Qyo07KJ1Tg/time_calculator.py", line 53, in add_time
re = (str(new_hours)+":"+str(new_mi)+' '+am_pm+', '+days[pos].capitalize())
IndexError: list index out of range
``````

I think you are iterating more than 6 times, then passing it to the pos variable. You’ll need to find a way to loop through your list of days without exceeding 6 as you list of days’ index is between 0 & 6.