![]() |
![]() First Summer 2006 |
Then we will try to solve this problem:
Write a program that
User input is in color.
Extra credit if you can deal with the case that the first time is later than the second time:Please enter the first time: 0900 Please enter the second time: 1730 8 hours 30 minutes
Please enter the first time: 1730 Please enter the second time: 0900 15 hours 30 minutes
You, of course, have to write your program in Python.frilled.cs.indiana.edu%java Fifteen Please enter the first time: 0920 Please enter the second time: 1025 1 hours 5 minutes frilled.cs.indiana.edu%java Fifteen Please enter the first time: 1025 Please enter the second time: 0920 22 hours 55 minutes frilled.cs.indiana.edu%
Here's the code as developed on Wednesday in class with Nick Quagliara:
a = raw_input("Please enter the first time:") b = raw_input("Please enter the second time:") h1 = a[0:2] m1 = a[2:4] h2 = b[0:2] m2 = b[2:4] time1 = (int(h1) * 60) + int(m1) time2 = (int(h2) * 60) + int(m2) d = time2 - time1 print "Hours", d / 60, "Minutes", d % 60