0

For example:

# 5 second response, if user doesn't do it in 5 seconds, then quit() 
a = input('Stack Overflow is cool')

if a == yes
    print('Harold882')
else: 
    print('asdf')

How can you do that, or just make a timer in general?

I also tried making different timers, but they didn't work.

Harold882
  • 9
  • 4
  • 4
    Does this answer your question? [Keyboard input with timeout?](https://stackoverflow.com/questions/1335507/keyboard-input-with-timeout) – Andrew-Harelson Oct 19 '21 at 02:10

1 Answers1

1

You could do something like this:

import time
from threading import Thread

answer = None

def check():
    time.sleep(5)
    if answer == None:
        print("Too Slow")
    elif answer == 'yes':
        print('Harold882')
    else:
        print('asdf')
    

Thread(target = check).start()

answer = input("Stack Overflow is cool: ")

using the time and threading modules.

krmogi
  • 2,588
  • 1
  • 10
  • 26