I am making a project where users are asked to enter multiple input within a stipulated time. This is what I Tried:
import time
import threading
def timer():
global sec
sec =21
while sec != 0:
sec -= 1
time.sleep(1)
print("Seconds left:",sec)
print("\nTime Over")
def ask_words():
while sec >0:
#Ask Question#
timer = threading.Thread(target = timer)
timer.start()
ask_words()
Output:
This is the output
Problem: After the time is up I can add the last input after which the code is getting completed because the code(input) is executed after which the sec variable is becoming Zero so the program is waiting for the user to enter something. I don't know how to fix it.