import random # Multiplication Quiz print("Welcome to the Multiplication Quiz!") name = input("Please enter your name: ") print("\nInstructions") print("----------------------------------") print("1. You will be asked multiplication questions.") print("2. Type the correct answer and press Enter.") print("3. Enter whole numbers only.") print("4. Your score will be shown at the end.\n") # Ask how many questions while True: try: total_questions = int(input("How many questions would you like (1-20)? ")) if 1 <= total_questions <= 20: break else: print("Please enter a number between 1 and 20.") except ValueError: print("Please enter a valid whole number.") print(f"\nGood luck, {name}!") print("----------------------------------") score = 0 results = [] # Quiz for question in range(1, total_questions + 1): num1 = random.randint(1, 12) num2 = random.randint(1, 12) correct_answer = num1 * num2 while True: try: answer = int(input(f"\nQuestion {question}: {num1} x {num2} = ")) break except ValueError: print("Please enter a valid whole number.") if answer == correct_answer: print("Correct!") score += 1 results.append(f"{question}. Correct") else: print(f"Incorrect. The correct answer was {correct_answer}.") results.append(f"{question}. Incorrect") # Results print("\n----------------------------------") print("Quiz Results") print("----------------------------------") print(f"Name: {name}") print(f"Questions Answered: {total_questions}") print(f"Correct Answers: {score}") print(f"Incorrect Answers: {total_questions - score}") percentage = (score / total_questions) * 100 print(f"Score: {percentage:.0f}%") if percentage == 100: print("Excellent! You got every question correct.") elif percentage >= 80: print("Very good work!") elif percentage >= 60: print("Good effort. Keep practising.") elif percentage >= 40: print("You're making progress. Keep practising your multiplication facts.") else: print("Keep practising and try the quiz again.") # Game history option print("\n----------------------------------") history = input("Would you like to see your game history? (yes/no): ") if history.lower() == "y" or history.lower() == "yes": print("\nGame History") print("----------------------------------") for result in results: print(result) else: print("Game history skipped.") print("\nThank you for playing!")