In add_time function strange problem

hello everyone
I have finished coding my 'add_time ’ project and it is working pretty well as it passes all the tests on my computer. However, it failed all the tests on the replite though the outputs are the same as the expected outputs. what I am missing here.
this is my code:

def add_time(start, duration,start_day = ''):
    frstlst=[]

    start_day = start_day.capitalize()
    if start_day != '':
        frstlst.append(start_day)

    #start variables
    splitedstrt = start.split()
    hoursMinuts = splitedstrt[0]
    splitedHourMinuts = hoursMinuts.split(':')
    sthour = splitedHourMinuts[0]
    sminuts = splitedHourMinuts[1]
    ending = splitedstrt[1]

    #douration variables
    splitedDuration = duration.split(':')
    Dhour = splitedDuration[0]
    Dminut = splitedDuration[1]
    dayName = start_day.capitalize()

    days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

    mints_total = int(sminuts) + int(Dminut)
    hours_total = int(sthour) + int(Dhour)

    if mints_total >= 60:
        mints_total = mints_total - 60
        hours_total = hours_total + 1

    daysn = int(hours_total / 24)+1# I added 1 to compensate the missing decimals
    nxtdays = ''

    if ending == 'PM':
        hours_total = hours_total + 12

    moderator = hours_total % 24

    if moderator<12:
        ending = ' AM'
    if moderator>=12:
        ending = ' PM'
        moderator = moderator-12

    if moderator == 0:
        moderator=12


    if start_day not in frstlst:
        finalresult = moderator, ':', "%02d" % (mints_total), ending, nxtdays

        if hours_total >= 24 and hours_total<48:
            nxtdays = ' (next day)'
            finalresult = moderator, ':', "%02d" % (mints_total), ending, nxtdays
        if hours_total >= 36:
            nxtdays = ' ' + '(' + str(daysn) + ' days later' + ')'
            finalresult = moderator, ':', "%02d" % (mints_total), ending, nxtdays

    if start_day in frstlst:
        dayName = ', ' + start_day
        finalresult = moderator, ':', "%02d" % (mints_total), ending, dayName, nxtdays
        if hours_total >= 24 and hours_total >= 36:

            dayindex = days.index(start_day)
            dayName = ', ' + str(days[(dayindex+daysn)%7 ] )
            nxtdays = ' ' + '(' + str(daysn) + ' days later' + ')'
            finalresult = moderator, ':', "%02d" % (mints_total), ending, dayName, nxtdays

        if hours_total >= 26 and hours_total < 36:
            daysn=daysn-1
            dayindex = days.index(start_day)
            dayName = ', ' + str(days[(dayindex + daysn) % 7])
            nxtdays = ' (next day)'
            finalresult = moderator, ':', "%02d" % (mints_total), ending, dayName, nxtdays



    finalresult1 = ''.join(str(x) for x in finalresult)
    print(finalresult1)

#these are all the tests I ran on my computer:
add_time("3:30 PM", "2:12")
print('5:42 PM','expected')
add_time("11:55 AM", "3:12")
print('3:07 PM','expected')
add_time("9:15 PM", "5:30")
print('2:45 AM (next day)','expected')
add_time("11:40 AM", "0:25")
print('12:05 PM','expected')
add_time("2:59 AM", "24:00")
print('2:59 AM (next day)','expected')
add_time("11:59 PM", "24:05")
print('12:04 AM (2 days later)','expected')
add_time("8:16 PM", "466:02")
print('6:18 AM (20 days later)','expected')
add_time("5:01 AM", "0:00")
print('5:01 AM','expected')
add_time("3:30 PM", "2:12", "Monday")
print('5:42 PM, Monday','expected')
add_time("2:59 AM", "24:00", "SATURDAY")
print('2:59 AM, Sunday (next day)','expected')
add_time("11:59 PM", "24:05", "Wednesday")
print('12:04 AM, Friday (2 days later)','expected')
add_time("8:16 PM", "466:02", "tuesday")
print('6:18 AM, Monday (20 days later)','expected')

after each function call I print the expected output with the word ‘expected’ at the end so I got these outputs:

5:42 PM
5:42 PM expected
3:07 PM
3:07 PM expected
2:45 AM (next day)
2:45 AM (next day) expected
12:05 PM
12:05 PM expected
2:59 AM (next day)
2:59 AM (next day) expected
12:04 AM (2 days later)
12:04 AM (2 days later) expected
6:18 AM (20 days later)
6:18 AM (20 days later) expected
5:01 AM
5:01 AM expected
5:42 PM, Monday
5:42 PM, Monday expected
2:59 AM, Sunday (next day)
2:59 AM, Sunday (next day) expected
12:04 AM, Friday (2 days later)
12:04 AM, Friday (2 days later) expected
6:18 AM, Monday (20 days later)
6:18 AM, Monday (20 days later) expected

this is the replite link:

when you ask for help please give link to the challenge, and in cases like this to your replit, please


can you point out which part of your code returns the answer?

1 Like

and this is the part that returns the answer:

finalresult = hours_total, ':',"%02d"%(mints_total),' ' ,ending, dayName, nxtdays
    finalresult1 = ''.join(str(x) for x in finalresult)
    print(finalresult1)
this is the replite link:
https://replit.com/@abdelrhani43/boilerplate-time-calculator-1

are you sure that that part is returning? I don’t see any return in there

1 Like

problem fixed. thanks for your help ilenia

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.