The time module
The time module allows the user to directly get the time, in seconds, since 1970 (See: https://docs.python.org/3/library/time.html). This means that we can subtract the time before from time after to see how long it has been, namely how long it took the user to finish the typing test. From there, it is as easy as printing the result. You can round the time using int to get a purely seconds result without milliseconds.
The code
# Import the time library
import time
# Calculate the start time
start = time.time()
# Code here
# Calculate the end time and time taken
end = time.time()
length = end - start
# Show the results : this can be altered however you like
print("It took", length, "seconds!")
Answer from Larry the Llama on Stack OverflowThe time module
The time module allows the user to directly get the time, in seconds, since 1970 (See: https://docs.python.org/3/library/time.html). This means that we can subtract the time before from time after to see how long it has been, namely how long it took the user to finish the typing test. From there, it is as easy as printing the result. You can round the time using int to get a purely seconds result without milliseconds.
The code
# Import the time library
import time
# Calculate the start time
start = time.time()
# Code here
# Calculate the end time and time taken
end = time.time()
length = end - start
# Show the results : this can be altered however you like
print("It took", length, "seconds!")
You can use the built-in time library:
import time
str_to_type = "The cat is catching a mouse."
start_time = time.perf_counter()
print("Type: '" + str_to_type + "'.")
typedstring = input()
if typedstring == str_to_type:
end_time = time.perf_counter()
run_time = end_time - start_time
print("You typed '" + str_to_type + "' in", str(run_time), "seconds.")
How to make a timer ?
Time.time() use as a timer
Python Timer Functions: Three Ways to Monitor Your Code – Real Python
Not to be confused with threading.Timer.
Count down timer Python
Videos
Hello guys ! I’m starting with python a week ago, I don’t have all the knowledge etc…, but I’m very curious and I wish to know a method or how to make a Timer in python… like my timer start at 35min and decrease to 0 or to 0 to 35. If anybody have an idea how to do this, I'll take it !! See you ! 🐍