Hi,
So I am trying to complete the time calculator project and the code I wrote is working in pycharm on my computer but wont work in replit and I have no idea why. If someone could help that would be awesome, thank you!
Your code so far
def add_time(start_time, duration_time, weekday = ""):
split_start_time = start_time.split()
time = (split_start_time[0])
time_split = time.split(":")
hour_1 = time_split[0]
minute_1 = time_split[1]
am_pm = split_start_time[1]
format_jk = ""
weekdays = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
duration_time_split = duration_time.split(":")
hour_d = duration_time_split[0]
minute_d = duration_time_split[1]
total_minute = int(minute_d) + int(minute_1)
if am_pm == "AM":
total_hour = int(hour_1) + int(hour_d)
else:
total_hour = int(hour_1) + 12 + int(hour_d)
total_time = str(total_hour) + ":" + str(int(total_minute)).zfill(2)
if int(total_minute) > 60:
total_hour = int(total_hour) + 1
total_minute = int(total_minute) - 60
days_passed = int((total_hour / 24))
j = "(" + str(days_passed)
k = " days later)"
if days_passed >= 2:
format_jk = str(j) + str(k)
new_hour = int(total_hour) - 24 * int(days_passed)
if new_hour == 0:
total_time = str(12) + ":" + str(int(total_minute)).zfill(2)
pa = "AM"
elif new_hour < 12:
pa = "AM"
total_time = str(int(total_hour) - 24 * (int(days_passed))) + ":" +
str(int(total_minute)).zfill(2)
elif new_hour == 12:
total_time = str(int(total_hour) - 24 *(int(days_passed))) + ":" +
str(int(total_minute)).zfill(2)
pa = "PM"
else:
pa = "PM"
total_time = str(int(total_hour) - 24 * (int(days_passed))) + ":" +
str(int(total_minute)).zfill(2)
elif days_passed >= 1:
format_jk = "(next day)"
if total_hour > 36:
total_time = str(int(total_hour) - 36) + ":" + str(int(total_minute)).zfill(2)
else:
total_time = str(int(total_hour) - 24) + ":" + str(int(total_minute)).zfill(2)
if total_hour >= 36:
pa = "PM"
else:
pa = "AM"
else:
if total_hour >= 12:
new_hour = int(total_hour) - 12
if new_hour == 0:
total_time = "12" + ":" + str(int(total_minute)).zfill(2)
else:
total_time = str(int(total_hour) - 12) + ":" + str(int(total_minute)).zfill(2)
pa = "PM"
else:
pa = "AM"
total_time = str(int(total_hour)) + ":" + str(int(total_minute)).zfill(2)
if weekday:
weekday = weekdays.index(weekday.title())
new_weekday = int((weekday + days_passed) % 7)
weekday = weekdays[new_weekday]
format_1 = (total_time + " "+ pa + "," + " " + weekday)
format_2 = (total_time + " " + pa)
format_3 = (total_time + " " + pa + " " + format_jk)
format_4 = (total_time + " " + pa + "," + " " + str(weekday).capitalize() + " " + format_jk)
if format_jk == "":
if weekday:
return((format_1))
else:
return((format_2))
elif weekday == "":
return((format_3))
else:
return((format_4))
Challenge: Time Calculator
Link to the challenge: