import sys
for line in sys.stdin.read().splitlines():
start, end = line.split()
sh, sm = map(int, start.split(":"))
eh, em = map(int, end.split(":"))
minutes = (eh * 60 + em - (sh * 60 + sm)) % (24 * 60) # % wraps past midnight
h, m = divmod(minutes, 60)
print(f"{start} to {end}: {h} h {m:02d} min")
Output Verified by running it on Python 3
09:15 to 17:45: 8 h 30 min
22:30 to 06:10: 7 h 40 min
13:00 to 13:00: 0 h 00 min
Python's % never returns a negative number for a positive divisor, so a negative difference (an overnight shift) wraps to the right value.
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!