Build a Time Calculator Project - Build a Time Calculator Project

Tell us what’s happening:

I don’t think I need help with the actual code right now. Ive been almost done for several days, but the tests keep timing out, and when I try to print the calls that are failing it doesn’t show up, or one will show up but after that it will stop working. I don’t think this is because of an issue with the code because when I first pull it up everything works fine but then after a few seconds it stops working. Has anyone else experienced this? It could be an issue with my wifi network.

Your code so far

def add_time(start, duration, start_day=''):
    #splitting up start
    start.split(' ')
    start_time = start.split(' ')[0]
    start_number = start_time.replace(':', ' ')
    start_hours = int(start_number.split(' ')[0])
    start_minutes = int(start_number.split(' ')[1])
    qualifier = start.split(' ')[1]
    #splitting up duration
    duration_number = duration.replace(':', ' ')
    duration_hours = int(duration_number.split(' ')[0])
    duration_minutes = int(duration_number.split(' ')[1])
    
    #adding times
    
    hours = start_hours + duration_hours
    minutes = start_minutes + duration_minutes
    days = 0
    while minutes >= 60:
        minutes = minutes - 60
        hours += 1
    while hours >= 12:
        if qualifier == 'AM':
            qualifier = 'PM'
        elif qualifier == 'PM':
            qualifier = 'AM'
            days += 1
        if hours >= 13:
            hours = hours - 12
    string_hours = str(hours)
    if minutes < 10:
        string_minutes = f'0{minutes}'
    else: string_minutes = str(minutes)
    time = f'{string_hours}:{string_minutes} {qualifier}'
    if start_day:
        day = start_day.lower()
        if day == 'sunday':
            day_number = 1
        if day == 'monday':
            day_number = 2
        if day == 'tuesday':
            day_number = 3
        if day == 'wednesday':
            day_number = 4
        if day == 'thursday':
            day_number = 5
        if day == 'friday':
            day_number = 6
        if day == 'saturday':
            day_number = 7
        #adding day numbers
        new_day_number = day_number + days
        while new_day_number > 7:
            new_day_number = new_day_number - 7
        
        if new_day_number == 1:
            new_day = 'Sunday'
        if new_day_number == 2:
            new_day = 'Monday'
        if new_day_number == 3:
            new_day = 'Tuesday'
        if new_day_number == 4:
            new_day = "Wednesday"
        if new_day_number == 5:
            new_day = 'Thursday'
        if new_day_number == 6:
            new_day = 'Friday'
        if new_day_number == 7:
            new_day = 'Saturday'
        

        if days < 1:
            new_time = f'{time}, {new_day}'
        elif days == 1:
            new_time = f'{time}, {new_day} (next day)'
        else:
            new_time = f'{time}, {new_day} ({days} days later)'

    else:
        if days < 1:
            new_time = time
        elif days == 1:
            new_time = f'{time} (next day)'
        else:
            new_time = f'{time} ({days} days later)'
        
    return new_time

print(add_time('11:59 PM', '24:05'))

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15

Challenge Information:

Build a Time Calculator Project - Build a Time Calculator Project

It looks like one of the loops is running infinitely.

Do you know which one? Or how I can figure out which one it is?

print("test begin")
print(add_time('11:43 PM', '24:20', 'tueSday'))
print("test end")

This test runs infinitely.

I added a print here:

while hours >= 12:
        print(hours)

And it prints 12 nonstop

In here something amiss can be noticed by taking a look at the condition and where/how the value is changed inside of the loop.

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