How to add a timer in Python
Hello!
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!
Thank you very much in advance!
You can use the getKey module, and clear the screen and re-print it out every second, like @CodingCactus’s typing speed test. That is probably the only way because otherwise they would have to redo it every time you clear the screen and it would be impossible.
@NoelBryan that aint what they were asking tho
@NoelBryan I don't print the screen every second in my typing speed test either
Ohh, I thought they meant a timer displaying on the screen. The only way to do that is my awnser. @CodingCactus
@CodingCactus
Please re-read my post. You don’t understand what I said.
@NoelBryan your post doesn't really make sense to me if i'm honest
Yeah, I didn’t mean a timer on screen, but thank you very much for your answer! @NoelBryan
@NoelBryan Ummmm......
@NoelBryan @CodingCactus
I stumbled upon this post is there a way to make one that displays the timer while having somebody put in input because I want to try something.
@BobNeo you can't have a clock counting down (being displayed) while waiting for an input, because an input will pause the program until something is input.
Oh yeah, that seems like it would work. @NoelBryan @CodingCactus
However, is there any easier way without importing getKey
@BobNeo
importing getkey isn't hard anyway, it is like importing time or any other library
@NoelBryan getkey still pauses the program like a normal input does
I know it’s just slow because repl.it takes awhile to import packages saying “importing getKey” @CodingCactus
@CodingCactus
I think what @NoelBryan means is you keep track of what keys were pressed without pressing enter like in an array and every second you print out the time. That would work.
@BobNeo Yes, that is how getkey works, you don't need to press enter
But you can't print out the time every second if there is no key pressed, because the program will wait for a key to be pressed until it does anything
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)
@Bookie0 did it help?
That won’t work. Run the code. @CodingCactus
Hey, I’m going to try it out rn but it seems pretty logic but thanks! @CodingCactus
So i tried it out, and it gave me an error on last line asking if i meant == instead of = , so i did that, but now it just gives me false instead of a number:

@CodingCactus
@NoelBryan works for me
Oh wait never mind you wrote = but i think you meant + and it works now @CodingCactus
@Bookie0 yh, that was a typo, it should be a
+
as you are just concatenatingOk yeah it worked. Thank you very much for your great help! :D @CodingCactus
@Bookie0 np
Told you it didn’t work. @CodingCactus
@NoelBryan but it does
Now it does @NoelBryan
@NoelBryan It was just an obvious typo, which you thought broke it or something
Except for the fact that your “obvious” type bookie0 didn’t recognize..............
@NoelBryan well, to me it looks like they recognised it
Then why did they comment? @CodingCactus
Because before I wrote that there was a problem, but then I commented to @CodingCactus that actually I resolved it @NoelBryan
@NoelBryan why are you focusing so heavily in this lol. Are you really bored or something?
Lol @CodingCactus
@Bookie0 This escalated quickly xD
Yeah lol @Tsadema