Hello there! So after submitting my asssignment I’ve been trying to figure out something (explained at the end).
Here is my solution to the problem:
def add_time(start, duration, week_day = ""):
hour = minute = day_night = new_time = ""
days_in_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
#taking the time_now in start apart
time_now = start.split()
hour_min_now = time_now[0].split(":")
hour = int(hour_min_now[0])
minute = int(hour_min_now[1])
day_night = time_now[1]
if day_night == "PM":
hour += 12
#taking the time_add in duration apart
time_add = duration.split(":")
hour_add = int(time_add[0])
minute_add = int(time_add[1])
#setting up the minutes
minutes = minute + minute_add
final_minute = minutes % 60
if final_minute < 10:
final_minute = "0" + str(final_minute)
#setting up the hours
final_hour = hour + hour_add + minutes // 60
final_hour_format = final_hour % 24
days = final_hour // 24
if week_day != "":
#little part to take care of spelling mistakes
week_day = week_day.lower().capitalize()
index = days_in_week.index(week_day)
new_index = (index + days) % 7
week_day = days_in_week[new_index]
#determining whether to print AM or PM
if final_hour_format > 12:
new_time = str(final_hour_format % 12) + ":" + str(final_minute) + " PM"
elif final_hour_format == 12:
new_time = "12:" + str(final_minute) + " PM"
elif final_hour_format == 0:
new_time = "12:" + str(final_minute) + " AM"
else:
new_time = str(final_hour_format) + ":" + str(final_minute) + " AM"
if week_day != "":
new_time += ", " + week_day
if days > 0:
if days == 1:
new_time += " (next day)"
else:
new_time += " ("+ str(days) +" days later)"
return new_time
print(add_time("3:30 PM", "2:12"))
When I ran the code, the console in Replit gave this output:
5:42 PM
............
----------------------------------------------------------------------
Ran 12 tests in 0.002s
OK
>
According to what I saw online, the output is supposed to look a little different. It runs the test but gives feedback on just the first input, and the remaining output in the console is written in red. Is it supposed to happen that way, or have a made a mistake somewhere? Please help if you can