Time Calculator - Scientific Computing with Python Projects

Hi! For a time calculator project, I am given a start time, add a duration to the time, and print out the result. I am stuck on how to change the output to either AM or PM depending on if the duration of the time causes the PM or AM of the start time to change to the other. For instance, if an hour and 30 minutes is added to 11:45 AM, the output should be 1:15 PM. Adding an hour and 30 minutes to 11:45 PM however changes the output to 1:15 AM. I would like to know how I can create the condition to change AM to PM or PM to AM. Thank you!

Try converting to metric 24 hour time.

11:43 pm becomes 23:43 (add 12)

1 am becomes 1:00.

From here, do all of the time adding math and then convert back to imperial time. 23:43 pm becomes 11:43 PM (subtract 12).

However, be careful because 00:43 should become 12:43 am, but 1:43 should become just 1:43 am. One is added 12 and the other is not despite having am.

AM and PM change every 12 hours.
So you can write something that goes over the total time in 12hour steps, check if it’s AM and if so, change to PM, if not, change to AM.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.