import random def maths_quiz(): score = 0 total_questions = 0 num_questions = 5 # for _ in range(num_questions): num1 = random.randint(1, 12) num2 = random.randint(1, 12) correct_answer = num1 * num2 print(f"What is {num1} * {num2}?") try: user_answer = int(input("Your answer: ")) total_questions += 1 if user_answer == correct_answer: print("Correct!") score += 1 else: print(f"Incorrect. The correct answer was {correct_answer}.") except ValueError: print("Invalid input. Please enter a number.") print(f"\nQuiz finished! You scored {score} out of {total_questions}.") maths_quiz()