import random

# Define a dictionary of quiz categories with their corresponding questions
quiz_categories = {
    "Math": [
        {
            "question": "What is the result of 2 + 2?",
            "choices": ["A. 1", "B. 3", "C. 4", "D. 5"],
            "correct_answer": "C"
        },
        {
            "question": "What is the result of 5 * 3?",
            "choices": ["A. 8", "B. 12", "C. 15", "D. 18"],
            "correct_answer": "C"
        },
        {
            "question": "What is the result of 10 - 6?",
            "choices": ["A. 2", "B. 3", "C. 4", "D. 5"],
            "correct_answer": "C"
        }
    ],
    "Technology": [
        {
            "question": "What does 'HTML' stand for?",
            "choices": ["A. Hyper Text Markup Language", "B. Home Tool Markup Language", "C. Hyperlinks and Text Markup Language", "D. None of the above"],
            "correct_answer": "A"
        },
        {
            "question": "Who is the CEO of Tesla?",
            "choices": ["A. Jeff Bezos", "B. Tim Cook", "C. Elon Musk", "D. Mark Zuckerberg"],
            "correct_answer": "C"
        },
        {
            "question": "What programming language is used to build Android apps?",
            "choices": ["A. Java", "B. Python", "C. C#", "D. Swift"],
            "correct_answer": "A"
        }
    ]
}

# Function to run the quiz game
def run_quiz(category):
    score = 0
    num_questions = 2  # Specify the number of questions to ask in each game

    # Select questions based on the chosen category
    selected_questions = random.sample(quiz_categories[category], num_questions)

    print("Welcome to the Quiz Game!")
    print("--------------------------")

    # Iterate over the selected questions
    for i, question in enumerate(selected_questions, start=1):
        print(f"Question {i}: {question['question']}")
        print("Choices:")
        for choice in question['choices']:
            print(choice)

        # Get the player's answer with error handling for invalid inputs
        while True:
            player_answer = input("Enter your answer (A, B, C, or D): ").upper()
            if player_answer in ['A', 'B', 'C', 'D']:
                break
            else:
                print("Invalid input! Please enter A, B, C, or D.")

        # Check if the answer is correct
        if player_answer == question['correct_answer']:
            print("Correct answer!")
            score += 1
        else:
            print("Incorrect answer!")

        print("--------------------------")

    # Display the player's score at the end of the game
    print("Quiz completed!")
    print(f"Your score: {score} out of {num_questions}")

# Get the player's preferred category
category = input("Choose a quiz category (Math/Technology): ")

# Run the quiz game with the chosen category
run_quiz(category)
