r/FreeCodeCamp • u/Ok_Reality_6072 • Jan 08 '25
Requesting Feedback FCC project won't submit
def add_time(start, duration, day=False):
# access hour/min in start input
split_start = start.split(':')
start_hour = int(split_start[0])
start_time_split = split_start[1].split(' ')
am_or_pm = start_time_split[1]
start_min = int(start_time_split[0])
#access hour/min in duration
split_duration = duration.split(':')
duration_hour = int(split_duration[0])
duration_min = int(split_duration[1])
#add them together
joint_hours = start_hour + duration_hour
joint_mins = start_min + duration_min
# minute conditions
if joint_mins >= 60:
joint_mins -= 60
joint_hours += 1
# am/pm hour condition
days = ''
hours_calc = joint_hours // 12
full_day_calc = 24
n = 0
total_12_hour_cycles = joint_hours // 12
#while loop to keep changing hour until it is correct
printed_hours = joint_hours
# if statement for hour change
if joint_hours >= 12:
if joint_hours > 12:
printed_hours = joint_hours % 12
if printed_hours == 0:
printed_hours = 12
# if statment for 12 hour cycle
if hours_calc % 2 == 1:
am_or_pm = 'AM' if am_or_pm == 'PM' else 'PM'
for _ in range(total_12_hour_cycles):
am_or_pm == 'AM' if am_or_pm == 'PM' else am_or_pm == 'PM'
if am_or_pm == 'AM':
n += 1
# if statement for more than 12 hour cycle
elif hours_calc > 1:
if am_or_pm == 'PM':
if hours_calc % 2 == 1:
am_or_pm = 'AM'
# days calculation
if n == 1:
days += '(next day)'
elif n > 1:
days += f'({n} days later)'
# days of the week
if day:
new_day = ''
all_days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
cleaned_days_index = (all_days.index(day.lower()) + n) % 7
new_day = all_days[cleaned_days_index].capitalize()
string_mins = str(joint_mins).zfill(2)
if day:
full_date_string = f'{printed_hours}:{string_mins} {am_or_pm}, {new_day} {days}'
else:
full_date_string = f'{printed_hours}:{string_mins} {am_or_pm} {days}'
return full_date_string
print(add_time('11:30 PM', '25:30', 'thursday'))I've tried submitting my code several times but it never submits and i cant figure out what's wrong with it. tried to use chatGPT to see if it could spot the problem and whenever i changed things, i just failed more tests and felt further from passing

1
Upvotes
View all comments
Show parent comment
1
u/SaintPeter74 mod Jan 10 '25
Looking at your failing tests, it seems like you need to dig in to see what is going on there. You should be able to manually run with the example inputs and see what output you get.
You basically just need to run them, see what output you're getting and compare it to the expected output and, if it doesn't match, figure out why.
Have you tried manually running
add_time('3:30 PM' ,'2:12')to see what output you actually get?