My code works perfectly fine on Atom but I just tried to complete the project by passing it on the repl but it seems like everything failed. Why? Please help.
Here is my code: (I assure you everything is properly indented)
def add_time(start, duration):
#All of the conversions of start
slist1 = start.split(’ ‘) #isolate time from AM/PM into list
stime = slist1[0] #isolate time into a str variable
ampm = slist1[1] #isolate AM/PM into a str variable
stime1 = stime.split(’:’) #split time by :
s_hrs = int(stime1[0]) #converted hours into int
s_mins = int(stime1[1]) #converted mins into int
#All of the conversions for duration
d_list_2 = duration.split(':') #split hrs from mins into a list
d_hrs = int(d_list_2[0]) #isolate duration hrs and turn into int
d_mins = int(d_list_2[1]) #isolate duration mins and turn into int
#General time conversion
if s_hrs >= 0 and s_hrs <= 12 and d_hrs >= 0 and d_hrs <= 12:
new_hrs = (s_hrs + d_hrs) - 12 #equation for addition of both start and duration hours excluding 12
if new_hrs == 0:
new_hrs = (s_hrs + d_hrs) #equation for addition of both start and duration hours if new_hrs 12 otherwise it equals 0
if s_mins >= 0 and s_mins <= 59 and d_mins >= 0 and d_mins <= 59:
new_mins = (s_mins + d_mins) - 60 #equation for addition of both start and duration minutes
#Final formula that converts all integers to strings
if new_mins < 10:
str_mins = str(new_mins)
str_mins = str_mins.zfill(2)
new_time = str(new_hrs) + ':' + str_mins
elif new_mins >= 10:
new_time = str(new_hrs) + ':' + str(new_mins)
#Defining if it is AM/PM
it_is_AM = 'AM'
it_is_PM = 'PM'
#Converting AM/PM
if ampm == it_is_AM:
a_or_p = it_is_AM
if new_hrs == 12:
a_or_p = it_is_PM
elif ampm == it_is_PM:
a_or_p = it_is_PM
if new_hrs == 12:
a_or_p = it_is_AM
new_time += ' ' + a_or_p
return new_time #Solution