Distance=200
import time
Time_started=time.ctime()
question=(input("has car gone pass sensor 1 \n:"))
if question=="yes":
print ("the time is",Time_started,"seconds")
Time_ended=time.ctime()
question2=(input("has car gone pass sensor 2 \n:"))
if question2=="yes":
print ("the time is",Time_ended,"seconds")
print ("")
Time_taken= (time.ctime() - Time_started)
print ("it took %f1 seconds" % Time_taken , "to travel 200m" )
i want to know if it is possible to take time.ctime away from each other to get the seconds by themselves
为什么不使用time.time()代替time.ctime()?
You can use: time.time()
and time.ctime(secs)
Time_started=time.time()
If you want to convert that to something user friendly, you can do:
print ("the time is",time.ctime(Time_started))
You said you only wanted time.ctime because it is user friendly, so you can do this:
Use time.time()
to initialize Time_started
and Time_ended
, and use them whenever you need to calculate something (eg, the difference between them). But when you want to print the time to the user, use time.ctime(Time_started)
or time.ctime(Time_ended)
. time.ctime will then return a pretty string that describes the time you supplied it with.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.