I have just gotten into python and am trying to create a quiz game. I would like to add a countdown timer of 2 minutes to my quiz so when the timer reaches zero the questions stop and says you are out of time. I also tried to do this with a stopwatch but couldn't figure out how to terminate play so if you know how to do that it would be just as good.
Note: I am NOT using pygame. Many other users have asked in previous threads.
This is the code I gathered from the other documents but it doesn't stop once it reaches 2 mins or 0 mins.
def countdown():
t = 60
while t:
mins, secs = divmod(t, 60)
timeformat = '{:02d}:{:02d}'.format(mins, secs)
print(timeformat, end='\r')
time.sleep(1)
t -= 1
print("You're out of time!\n")
sys.exit ("goodbye")
def main_game():
count_thread = threading.Thread(None, countdown)
question_4 = ("question 1?")
option_4 = (" a. 1 \n b. 5 \n c. 3 \n d. 7")
print(question_4)
print(option_4)
answer_4 = input (">")
if answer_4.lower()== "b":
score = score + 100
else:
print("Incorrect")
import time
start1 = time.time()
if start1 >= 120:
import sys
sys.exit
question_a = ("question?")
option_a = (" a. 7 \n b. 8 \n c. 2 \n d. 1")
print(question_a)
print(option_a)
answer_a = input (">")
if answer_a.lower()== "b":
score = score + 100
else:
print("Incorrect")
###rest of questions
end1 = time.time()
Both codes are two different versions I have tried. Both codes don't work. The bottom code times the play but it doesn't stop at the 2 minute mark.
Any help, advice, or feedback would be appreciated!