My Python Time Calculator Project code isn't working on repl

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

can you please provide the project link?

https://repl.it/@HernanTeran/fcc-time-calculator#time_calculator.py

Thank you!

Are you able to see it? I posted the url but it just shows a blank space

It looks like there was an issue with generating the embed. I went ahead and edited your post to display the link instead. :slight_smile:

Thank you so much. I also just realized I didn’t include code for (next day or n days) and for duration hours > 12. However, I have no idea how to go about doing both.

I am in the middle of a project of my own, but I gave your repl.it a quick glance.

  1. I don’t see code that allows for a third argument (the day of the week).
  2. It looks like you have some initialisation errors. I recommend doublechecking the flow of your if logics, as it looks like the one that initialises your new_hrs variable isn’t always firing.
  3. I see some negative numbers being produced in your results. That suggests an error in the math logic.

Got it thank you for your help. I am currently re-checking everything. Take care and good luck with your project!

1 Like