1

I am creating a sort of a game where the player has to guess a word within a given time limit everything is working accept i dont know how do i run a timer and take input at the same time that too in a loop. I tried some code but it took input then ran the timer and asked input again so one happened after the other and not simultaneously How do i fix it

Here is what i tried

import time
def countdown(seconds):
  while seconds > 0:
    seconds -= 1
    time.sleep(1)
seconds = 6
while seconds > 0:
    input = ("guess word : ")
    countdown(6)

^^ that is only a fraction of my code Full code here - https://sourceb.in/QYk1D9O2ZT

4
  • 4
    Tip: Have the timer run on a different thread. Have a look into the threading module. 1) Docs linked here. 2) Tutorial linked here. Commented Jun 4, 2022 at 19:56
  • Looks like this thread suggests how to do exactly what you want Python multithreading interrupt input() - not only run a timer, but actually stop the input function waiting for user to press enter after time has passed. Commented Jun 4, 2022 at 20:15
  • Welcome to Stack Overflow. " i dont know how do i run a timer and take input at the same time that too in a loop." What exactly does this mean? Is the timer supposed to make the user wait before typing again, make the user have to type within a time limit, or something else? What should happen when the timer runs out? Commented Jun 4, 2022 at 20:15
  • Python cancel raw_input/input via writing to stdin? Commented Jun 4, 2022 at 20:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.