Logic Error with Time Calculator

In some of the test cases on my code, either the meridian or the day is off. Help would be appreciated.
link to my replit: https://replit.com/@HarshilAv/boilerplate-time-calculator-1#time_calculator.py

I click on run and it shows no errors.
Can you explain where you got a problem? Or did you solve it already?

sorry I had uploaded an incorrect link. The new link should be correct

Ah ok, well the errors tell you pretty much what is wrong in the outputs.

Looking at the code it’s a bit hard to read because you create a lot of variables and just have a block of text.
Some comments and empty lines would make it more readable. Also avoiding inbetween variables unless needed - for example, just using “minutes” instead of “not_format_minutes”. Also at the end you somehow split “sol” and then combine it again - some comments explaining what you are doing might help.

Personally I’d recommend you streamline the code so you can easier track what is happening.

Though as the errors suggest, the failure is happening where you attribute AM/PM.
So… for example you got the if-conditions in line 33 with the very first being “if the day-part is equal and the formatted hours are bigger or equal to the start → change the date”.
Ofcourse then you fail the test for adding 0:00 time, because then new time will be identical to the old, but your code then says the day changed.

Or in line 25, where it suggest you can ONLY change the day-count if the start-time would be PM. That doesn’t sound right.
How would you do this by hand? Would you go through all 4 possible combinations of AM/PM with start and finish? I wouldn’t. I would swap the two ever 12 hours, add a daychange whenever it’s PM to AM and if I end up with 0, I’ll add 12. This way I don’t need to keep track of the starting time at all.

1 Like

Thank you for your detailed response. I will be sure to implement your suggested changes. Thanls

One error still persists in where the day does not display when the count_day_change variable is 0.

nevermind - I figured it out. Thanks