First Summer 2006

Lecture Notes Six: A Typical Programming Problem. (Getting Started with Python).
We will review the lab notes for today and the lab assignment.

Then we will try to solve this problem:

Write a program that

• reads two times in military format (0900, 1730) and
• prints the number of hours and minutes between the two times. Here is a sample run.

User input is in color.

```Please enter the first time: 0900
Please enter the second time: 1730
8 hours 30 minutes```
Extra credit if you can deal with the case that the first time is later than the second time:
```Please enter the first time: 1730
Please enter the second time: 0900

15 hours 30 minutes```
Here's a sample run with your program:
```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%```
You, of course, have to write your program in Python.

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```

Last updated: May 17, 2006 by Adrian German for A201/A597