# MMC 101COS - Quiz Quest # Multiplication Quiz for Year 9 students import random # Displays the introduction to the quiz def introduction(): print("=" * 40) print(" MULTIPLICATION QUIZ QUEST") print("=" * 40) print("Test your multiplication skills!") print("You will answer 10 questions.") print("Good luck!\n") # Gets a valid number from the player def get_answer(): while True: answer = input("Your answer: ") try: return int(answer) except ValueError: print("Please enter a whole number.") # Creates a random multiplication question def create_question(): number1 = random.randint(1, 12) number2 = random.randint(1, 12) correct_answer = number1 * number2 question = f"{number1} x {number2}" return question, correct_answer # Gives feedback based on the final score def final_feedback(score, total_questions): percentage = (score / total_questions) * 100 print("\n" + "=" * 40) print("QUIZ COMPLETE!") print("=" * 40) print(f"Your score: {score}/{total_questions}") print(f"Percentage: {percentage:.0f}%") if percentage == 100: print("Amazing! Perfect score!") elif percentage >= 80: print("Excellent work!") elif percentage >= 60: print("Good job! Keep practising.") elif percentage >= 40: print("Not bad! More practice will help.") else: print("Keep practising. You can improve!") print("=" * 40) # Runs one complete quiz def play_quiz(): score = 0 total_questions = 10 for question_number in range(1, total_questions + 1): print(f"\nQuestion {question_number} of {total_questions}") question, correct_answer = create_question() print(question) user_answer = get_answer() if user_answer == correct_answer: print("Correct! Well done!") score = score + 1 else: print("Incorrect.") print(f"The correct answer was {correct_answer}.") final_feedback(score, total_questions) # Main program introduction() name = input("What is your name? ").strip() # Makes sure the player enters a name while name == "": print("Please enter your name.") name = input("What is your name? ").strip() print(f"\nGood luck, {name}!") # Allows the player to play more than once while True: play_quiz() play_again = input( "\nWould you like to play again? (y/n): " ).lower().strip() if play_again == "n": print(f"\nThanks for playing, {name}!") break elif play_again == "y": print("\nStarting a new quiz...") else: print("I didn't understand that, so the quiz will now end.") break