Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing the time between 2 points in a program in Python [duplicate]

Tags:

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.

like image 231
matvey-tk Avatar asked Jul 01 '16 05:07

matvey-tk


People also ask

How do I get the time difference between two times in Python?

To get a time difference in seconds, use the timedelta. total_seconds() methods. Multiply the total seconds by 1000 to get the time difference in milliseconds. Divide the seconds by 60 to get the difference in minutes.

How do you find the distance between two points in Python?

The math. dist() method returns the Euclidean distance between two points (p and q), where p and q are the coordinates of that point.

How do you print the same number and time in Python?

In Python, we utilize the asterisk operator to repeat a string. This operator is indicated by a “*” sign. This operator iterates the string n (number) of times.


1 Answers

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.

like image 60
shiva Avatar answered Feb 15 '23 23:02

shiva