Scientific Computing with Python Projects - Time Calculator

getting assertion error despite outputting sometime

Your code so far

def days_later(days_added):
    if days_added == 1:
        return '(next day)'
    elif days_added > 1:
        return f'({days_added} days later)'
    else:
        return ''

def add_time(start, duration, day = False):
    week_days = [
        "monday",
        "tuesday",
        "wednesday",
        "thursday",
        "friday",
        "saturday",
        "sunday"
    ]

    ndays = 0
    initial_hours, initial_mins = start.split(":")
    if "12" in initial_hours and "AM" in initial_mins:
        initial_hours = '0'
    initial_mins, initial_period = initial_mins.split(" ")
    added_hours, added_minutes = duration.split(":")
    initial_hours, initial_mins = int(initial_hours), int(initial_mins)
    added_minutes, added_hours = int(added_minutes), int(added_hours)
    new_period = initial_period
    if "PM" in initial_period:
        initial_hours += 12
    total_minutes = initial_mins + added_minutes + ((initial_hours + added_hours) * 60)
    minutes_display = round(total_minutes % 60)
    minutes_left = total_minutes
    ndays = int((total_minutes / 1440))
    if total_minutes >= 1440:
        minutes_left = total_minutes % 1440
    hours_left = int(minutes_left / 60)
    if minutes_left <= 720:
        new_period = "AM"
    else:
        new_period = "PM"
        hours_left = hours_left - 12

    if hours_left == 0:
        hours_left = 12

    end_result = f'{hours_left}:{minutes_display:02} {new_period}'

    if day:
        day = day.lower()
        selected_day = int(((week_days.index(day)) + ndays) % 7)
        current_day = week_days[selected_day]
        end_result += f", {current_day.capitalize()} {days_later(ndays)}"
    else:
        end_result = " ".join((end_result, days_later(ndays)))
    


    return(end_result)

Your browser information:

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

Challenge: Scientific Computing with Python Projects - Time Calculator

Link to the challenge:

What assertion error are you getting?

When you see:

AssertionError: '3:07 PM ' != '3:07 PM'

this means you were supposed to return '3:07 PM',
but you instead returned '3:07 PM '

1 Like