# a. Title: Maths Quiz # b. Author: Dima Bykov # c. Date: 27/05/2026 # d. Ver: 2 # e. Purpose: To present random numbers that would be used in the question with tier-based encouragement. import random def script(): print("Welcome to my Mathematics Quiz!") print("I am going to ask you mathematical questions. Have fun!\n") score = 0 total_questions = 10 # Loop 10 times for i in range(1, total_questions + 1): # Determine the random numbers for the current question num_1 = random.randint(1, 10) num_2 = random.randint(1, 10) correct_answer = num_1 * num_2 print(f"--- Question {i} of {total_questions} ---") # Asking the user the question with crash protection while True: try: answer = int(input(f"What is {num_1} x {num_2}? ")) break # Stops the loop if the number is valid except ValueError: print("Invalid input. Please enter a valid number") # Checking input versus the correct answer if answer == correct_answer: print("You got it right!") score += 1 elif answer < correct_answer: print(f"Too low! The answer is {correct_answer}.") else: print(f"Too high! The answer is {correct_answer}.") print(f"Current Score: {score}\n") # Final score breakdown print("--- Quiz Finished! ---") print(f"Your final score is {score} out of {total_questions}.") # Encouragement if score >= 8: print("Wow! You are an absolute math genius!") elif score >= 5: print("Great effort! Keep it up!") else: print("Give it another shot, practice makes perfect.") print() # Adds an empty line for better spacing # Restarting the program restart = input("Would you like to restart the program? ").lower().strip() if restart in ["yes", "y"]: script() elif restart in ["no", "n"]: print("Exiting program. Thank you for playing!") else: print("Invalid character. Exiting program.") script()