Hi guys! I am new to Python and am currently doing a time calculator project and when i did my run test, my code failed with 2 tests my code is below. Can someone assist me where i am missing it. here is the link to my code https://repl.it/@KayDeeSibbs/boilerplate-time-calculator#time_calculator.py
Your code so far
def add_time(start, duration, day_of_week=""):
start_1 = [s.split() for s in start.split(":")]
duration_1 = duration.split(":")
hours = int(start_1[0][0]) + int(duration_1[0])
minutes = int(start_1[1][0]) + int(duration_1[1])
if minutes > 60:
minutes = minutes - 60
hours = hours + 1
else:
pass
# Converting minutes to hours and PM to AM and vice versa
day_format = start_1[1][1]
if day_format == "AM" and hours < 12:
day_format = "AM"
elif day_format == "AM" and hours >= 12:
day_format = "PM"
elif day_format == "PM" and hours < 12:
day_format = "PM"
elif day_format == "PM" and hours >= 12:
day_format = "AM"
# Adding a leading zero to minutes less than 10
if minutes < 10:
minutes = str(minutes).zfill(2)
# Converting hours to days
days = 0
days_later = 0
if hours > 12:
number_of_days = hours / 24
if number_of_days >= 1:
days = round(number_of_days)
elif number_of_days < 1:
if day_format == "AM":
days = 1
hours = hours % 12
days_later = days
if hours % 12 == 0:
hours = 12
elif hours < 12:
days = 0
days_later = days
# Determining the day of the week
days_of_week = [
"monday", "tuesday", "wednesday", "thursday", "friday", "saturday",
"sunday"
]
for day in days_of_week:
day_of_week = day_of_week.lower()
if day_of_week == day:
day_of_week = day
index_of_day = days_of_week.index(day_of_week)
if days_later <= 7:
new_day = days_later + index_of_day
if days_later > 7:
another_day = days_later - 7
new_day = another_day + index_of_day
if new_day > 6:
new_day = ((new_day + 1) % 7) - 1
new_day_of_week = days_of_week[new_day].capitalize()
if day_of_week == "":
if days_later == 0:
new_time = f"{hours}:{minutes} {day_format}"
elif days_later == 1:
new_time = f"{hours}:{minutes} {day_format} (next day)"
else:
new_time = f"{hours}:{minutes} {day_format} ({days_later} days later)"
if day_of_week != "":
if days_later == 0:
new_time = f"{hours}:{minutes} {day_format}, {new_day_of_week}"
elif days_later < 2:
new_time = f"{hours}:{minutes} {day_format}, {new_day_of_week} (next day)"
else:
new_time = f"{hours}:{minutes} {day_format}, {new_day_of_week} ({days_later} 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/87.0.4280.88 Safari/537.36
.
Challenge: Time Calculator
Link to the challenge: