Build a Time Calculator Project - Build a Time Calculator Project

Tell us what’s happening:

I put changing in every 12 hours, but for some reason it shows that I did something wrong only one test didnt accept

Your code so far

def check_day(day, days):
    week_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
    index_d = week_days.index(day)
    for i in range(days):
        index_d += 1
        if index_d == 7:
            index_d = 0
    return week_days[index_d]
def add_time(start, duration, day=''):
    part_of_day = start.split()[1]
    hours = 12
    days = 0
    new_str = ''
    time_start = float(start.replace(':', '.').split()[0])
    time_duration = float(duration.split(':')[0]) * 60 + float(duration.split(':')[1])
    minutes_counter = int(round(float(time_start - int(time_start)) * 100))
    time_start = int(time_start)
    for i in range(int(time_duration)):
        minutes_counter += 1
        if minutes_counter == 60:
            minutes_counter = 0
            time_start += 1
        if part_of_day == "PM" and time_start == hours:
            part_of_day = 'AM'
            time_start -= hours
            days += 1
        elif part_of_day == 'AM' and time_start == hours:
            part_of_day = 'PM'
            time_start -= hours
    time_start += float(minutes_counter/100)
    if part_of_day == 'AM' and time_start < 1:
        time_start = float(time_start + 12)
    new_time = str(f'{time_start:.2f} {part_of_day}').replace('.', ':')
    if day != '':
        day = day.lower().title()
        new_time += ', ' +  check_day(day, days)
    if days > 0:
        new_time += ' '
        if days == 1:
            new_str = '(next day)'
        elif days > 1:
            new_str = f'({days} days later)'
    new_time += new_str
    return new_time
print(add_time('11:59 PM', '24:05'))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Build a Time Calculator Project - Build a Time Calculator Project

Welcome to the forum :wave:

Please provide some more information

What test failed?

What is the expected output?

What is your output?

Did you test this?

print(add_time('11:59 AM', '00:05'))
1 Like

Ai dios im sorry

1 Like

Did you test this?

print(add_time('11:59 AM', '00:05'))

You see it? :+1:

1 Like

Yess thank you very much

1 Like