How to add a timer in Python
So I am making this sort of game where you have to make a sort of food. The way you make it is like this:
For example, if the user is asked to make a pizza, they have to type:
d c t (dough cheese tomato).
So then, they get money if they type the correct letters.
So my question is how to create a timer ⏱ that monitors how long it takes for the user to type those letters.
**The goal is for the timer to start when the input comes up, and ends once the user has clicked enter. **
Then, how much money they earn is based on how long it took. (But that will use an if statement, so i dont need help with that).
I hope you can help me, and thanks for taking time for checking this question!
you need to import time, then set the time that it started at, and then minus that from the time that it ended (see code below)
import time timeStart = time.time() choice = input("Enter choice:\n") timeEnd= time.time() timeTaken = timeEnd - timeStart print("That took: " + str(timeTaken) + "seconds")