A straightforward application of:
- Prompt for user input.
- Start countdown (or count up) timer.
- Wait on user input (as timer counts down/up).
- If user inputs a correct response, conditional statement 1
- Else, conditional statement 2
- If user exceeds a preset time, timer expires and user is directed accordingly.
I've tried some of the solutions offered on this web site. However, in all cases, the count up/down timer seems to stop once the user input prompt is generated. In other words, the timer does not seem to run as a separate (background) thread.
import threading
import time
class TimerClass(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.event = threading.Event()
        self.count = 10
    def run(self):
        while self.count > 0 and not self.event.is_set():
            print (self.count)
            int_answer = (int(input('Enter your age: '), base = 10)
            str_answer = str(int_answer)
            while str_answer == '':
                self.count -= 1
                self.event.wait(10)
                if (int_answer > 50) :
                    <do something>
                else:
                    <do somethingelse>
    def stop(self):
        self.event.set()
tmr = TimerClass()
tmr.start()
time.sleep(1)
tmr.stop()
The program should go to condition 1 if a response of > 50 is provided; else, go to condition 2 if a response of <= 50 is entered. The timer should expire after a period of 10 secs. if the user has not provided a response (with user notification).
 
     
    