1

I want the python program to wait for user specific char input, let's say "r"/"f", and to continue according to this char.

If after n hours none of these were input, I want the program to do something else. How can this be reached?

Samp
  • 9
  • 7

1 Answers1

2

Just use this

from threading import Timer

timeout = 10 #here is the time in second
t = Timer(timeout, print, ['Sorry, times up'])
t.start()
prompt = "You have %d seconds to choose the correct answer...\n" % timeout
answer = input(prompt)
t.cancel()
parmicciano
  • 88
  • 1
  • 8
  • When I'm doing this, script is still waiting for input even though I get "Sorry, times up" when no input was inserted. I want it to skip the waiting for input with timeout has passed. – Samp May 05 '22 at 16:02