### Thread: Help! Need help Creating program

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2012
Posts
4
Rep Power
0

#### Help! Need help Creating program

Hi Everyone, I am new here, and I was hoping to get a bit of help from anyone who could give me a hand with this program. I am having a hard time wrapping my head around it. I am going to want to use while loops to do the following:

Accept two times, in 24-hour notation (e.g. 2359 = 1 minute to midnight) and then print the time difference. For example, if time1 = 1215 and time2 = 1436 the difference is 2 hours 21 minutes. If time1 = 2230 and time2 = 0415 the difference is 5 hours 45 minutes.

I would really appreciate any help
2. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2012
Posts
16
Rep Power
0
Originally Posted by sght
Hi Everyone, I am new here, and I was hoping to get a bit of help from anyone who could give me a hand with this program. I am having a hard time wrapping my head around it. I am going to want to use while loops to do the following:

Accept two times, in 24-hour notation (e.g. 2359 = 1 minute to midnight) and then print the time difference. For example, if time1 = 1215 and time2 = 1436 the difference is 2 hours 21 minutes. If time1 = 2230 and time2 = 0415 the difference is 5 hours 45 minutes.

I would really appreciate any help
I don't know exactly how to do it neither, but take a look at the time module, it may help you further. http://docs.python.org/3.3/library/time.html
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2012
Posts
4
Rep Power
0
I actually ended up getting it late last night. Thanks

def getime(x):

s = raw_input('Enter time-%s (hh:mm): ' % x) # I used rawinput instead.
sh, sm = s.split(':')
return int(sm) + 60 * int(sh)

time1 = getime('1')
time2 = getime('2')

diff = time2 - time1

print "Difference: %d hours and %d minutes" % (diff//60, diff%60)