Printing the time between 2 points in a program in Python
Question:
I would like to know a way to time between two points in a program. In my situation I will ask the user 10 questions and after display the time it took for them to answer the question (example code below). How would i do this through something like import time ?
Example code:
timer.start
question1 = input("What is your favorite game ?")
timer.end
print(timer.time)
^
The timer.x thing is going to be replaced with your suggestions.
Answers:
How about this?
from datetime import datetime
start = datetime.now()
question1 = input("What is your favorite game ?")
end = datetime.now()
print(str(end - start))
import time
s=time.time()
question1 = input("What is your favorite game ?")
e=time.time()
print(e-s)
time.time()
Returns the time in seconds since the epoch as a floating point number.
I would like to know a way to time between two points in a program. In my situation I will ask the user 10 questions and after display the time it took for them to answer the question (example code below). How would i do this through something like import time ?
Example code:
timer.start
question1 = input("What is your favorite game ?")
timer.end
print(timer.time)
^
The timer.x thing is going to be replaced with your suggestions.
How about this?
from datetime import datetime
start = datetime.now()
question1 = input("What is your favorite game ?")
end = datetime.now()
print(str(end - start))
import time
s=time.time()
question1 = input("What is your favorite game ?")
e=time.time()
print(e-s)
time.time()
Returns the time in seconds since the epoch as a floating point number.