# Title: Math Quiz # Author: Josie Crowder # Date: 27/07/2026 # Ver: 4 # Purpose: To provide 12 maths questions for the user with a score that goes up with every right answer. import random def script(): print('Welcome to my maths quiz.') print('You will be asked 12 questions. Good luck') score = 0 questions_total = 12 # Loop 12 times for i in range(1, questions_total + 1): # Random number generator for questions num_01 = random.randint(1, 15) num_02 = random.randint(1, 15) right_answer = num_01 + num_02 # Asking questions while True: try: answer = int(input(f"What is {num_01} + {num_02} ?")) break # The loop stops if the number is valid except ValueError: print("Invalid number. Enter a valid number.") # Checking if user's input is correct if answer == right_answer: print('Your answer is correct.') score += 1 else: print(f'Your answer was not correct. The answer was {right_answer}') print(f'Score is: {score}/12') # End of the quiz print(f"{score}/{questions_total} is your final score.") print("The quiz has finished.") script()