Challenge: Time Calculator
Link to the challenge:
My code doesn’t run… IDK what is the issue
Here is my code:
def add_time(start, duration):
clock, period = start.split()
time, ap = start.split(" ")
hour, minute = clock.split(":")
addHour, addMinute = duration.split(":")
newHour = int(hour) + int(addHour)
newMin = int(minute) + int(addMinute)
answer = str(newHour) + ":" + str(newMin) + " " + ap
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (
</>) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
If this is the correct format - your
return is outside the function.
Also this code will fail the tests because you don’t take into account hours and minutes can “overflow”. It will happily return results like “426:63 AM” which isn’t a real time.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.