Scientific Computing with Python Projects - Time Calculato

Tell us what’s happening:
uhm so I finished with the time calculator of which I manually tested myself on visual studio and everything ran smoothly but a test is giving me error on replit, the test about add_time(“9:15 PM”, “5:30”))

Your code so far
def add_time(start, duration,day = False):
days_ofweek = [
‘Monday’, ‘Tuesday’,
‘Wednesday’, ‘Thursday’,
‘Friday’, ‘Saturday’,
f_days = 0
days = 0
hour = 0
extra_hr =0

halfday = int(12)
fullday = int(24)

#seperating the values and assigning them
start_h,start_m = start.split(‘:’)
start_min = start_m.split(’ ‘)[0]
time_ofday = start_m.split(’ ')[1]
d_hour,d_min = duration.split(“:”)

#sum total of hours and mins
hours = int(start_h)+int(d_hour)
mins = int(start_min) +int(d_min)
#adjusting minutes to hour if it is over 60 and getting the extra min left
if mins >=60:
extra_hr,mins = divmod(mins,60)
hours += extra_hr

if mins <= 9:
mins = f"{0}{mins}" #appending 0 to the min if it is less than 9 to make it double digits

#if its noon and total hour is above 12 and total hour/24 has a remainding meaning next day and over again till there’s no remainder
if time_ofday == (“PM”) and hours > fullday:
if hours % fullday >= 1.0:

if hours > fullday:
f_days,hour = divmod(hours,24)
days += f_days

hour = hours % halfday
if hour == 00:
hour += 12

tth = hours
while True:
if tth < halfday:
elif tth >= halfday:
if time_ofday == “AM”:
time_ofday = “PM”
elif time_ofday == “PM”:
time_ofday = “AM”
tth -= halfday

new_time = f"{hour}:{mins} {time_ofday}"

if day:
dayC = day.capitalize()
selected_day = int((days_ofweek.index(dayC) + days ) % 7 )
current_day = days_ofweek[selected_day]
new_time += f", {current_day}"

if (days == 1):
return new_time + f" (next day)"
elif days > 1:
return new_time + f" ({days} days later)"

return new_time

Your browser information:

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

Challenge: Scientific Computing with Python Projects - Time Calculator

Link to the challenge:

Please provide a link to your replit and/or post the full error message.

(post deleted by author)

I have edited it to the post, seems it’s being reviewed. thanks for the assistance.

Make sure to properly edit the link - the forum tries to turn links into previews which doesn’t work for replit and you are left with a blank space.

The error is:

AssertionError: '2:45 AM' != '2:45 AM (next day)'
- 2:45 AM
+ 2:45 AM (next day)
 : Expected time to end with "(next day)" when it is the next day.

So you are not adding “(next day)” properly. Given all other tests pass, seems like only this one case has trouble.