import random
import time
num_questions = 10
score = 0
print('''
Welcome to the math quiz.
You will have 3 tries and 8 seconds to answer each question.
Good luck.
''')
time.sleep(3)
for question_num in range(num_questions):
max_chances = 3
current_chances = 0
num1 = random.randint(0, 9)
num2 = random.randint(0, 9)
correct_answer = num1 * num2
while current_chances < max_chances:
current_chances += 1
user_answer = input('#%s: %s * %s = ' % (question_num+1, num1, num2))
if int(user_answer) == correct_answer:
print('Correct.')
break
else:
if current_chances == max_chances:
print('Out of tries. Please wait for the next question.')
time.sleep(1)
else:
print('Not quite. Try again.')
continue
I have this program that asks 10 math questions with 3 tries per question. This is for a practice project I am doing from Automate the Boring Stuff with python in which the directions read:
To see how much PyInputPlus is doing for you, try re-creating the multiplication quiz project on your own without importing it. This program will prompt the user with 10 multiplication questions, ranging from 0 × 0 to 9 × 9. You’ll need to implement the following features: • If the user enters the correct answer, the program displays “Correct!” for 1 second and moves on to the next question. • The user gets three tries to enter the correct answer before the program moves on to the next question. • Eight seconds after first displaying the question, the question is marked as incorrect even if the user enters the correct answer after the 8-second limit.
I believe I've met all the requirements besides the 8-second limit. I'm not exactly sure how to implement this into my code. The book has not yet introduced asyncio or threading, some of the ideas friends of mine have suggested, and I'm not exactly sure what other way I could implement a sort of timer to this program. Would anyone be able to help? Thank you.