mport time; # This is required to include time module. from time import mktime; from datetime import datetime ''' ticks1 = time.time() #ticks2= 1434370060 print ("Number of ticks (seconds) since 12:00am, January 1, 1970:", ticks1) print('\n') localtime1 = time.localtime(ticks1) print ("Local current time :", localtime1) print('\n') localtime2 = time.localtime(ticks2) print ("Local current time :", localtime2) print('\n') readabletime1 = time.asctime( localtime1 ) print ("Local current time :", readabletime1) print('\n') readabletime2 = time.asctime( localtime2 ) print ("Local current time :", readabletime2) print('\n') ''' def calcAveSpeed (t1, t2, dist): time1tuple = t1.timetuple() time2tuple = t2.timetuple() start=mktime(time1tuple) end=mktime(time2tuple) #http://stackoverflow.com/questions/6999726/how-can-i-convert-a-datetime-object-to-milliseconds-since-epoch-unix-time-in-p totTime=end-start speed = dist/totTime return speed distance = 500 # ask the user to enter.... validate (can't be negative can't be letters) dt1 = datetime(2012, 10, 18, 12, 00, 00) dt2 = datetime(2012, 10, 18, 12, 2, 58) aveSpeed= calcAveSpeed(dt1, dt2, distance); print(aveSpeed, 'km/s') distance = 750 dt1 = datetime(2012, 10, 18, 12, 00, 00) # let the user enter this and validate dt2 = datetime(2012, 10, 18, 13, 3, 58) aveSpeed= calcAveSpeed(dt1, dt2, distance); print(aveSpeed, 'km/s')
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question