Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
December 3rd, 2012, 10:55 PM
 sght
Registered User

Join Date: Dec 2012
Posts: 4
Time spent in forums: 22 m 48 sec
Reputation 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
December 4th, 2012, 01:39 PM
 leeuw01
Registered User

Join Date: Dec 2012
Posts: 16
Time spent in forums: 5 h 51 m 50 sec
Reputation Power: 0
Quote:
 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
December 4th, 2012, 09:16 PM
 sght
Registered User

Join Date: Dec 2012
Posts: 4
Time spent in forums: 22 m 48 sec
Reputation 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)

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Help! Need help Creating program