import random
quiz_questions = {
    "Mathematics": {
        "What is the result of 2 + 2?": "A",
        "What is the square root of 16?": "B",
        "What is the value of pi (π) to two decimal places?": "C",
        "What is the next number in the sequence: 1, 3, 5, 7, ...?": "D"
    },
    "Chemistry": {
        "What is the chemical symbol for water?": "A",
        "What is the atomic number of carbon?": "B",
        "What is the formula for sodium chloride?": "C",
        "What is the process by which a solid changes directly into a gas without passing through the liquid state?": "D"
    },
    "Science": {
        "What is the powerhouse of the cell?": "A",
        "Which planet is known as the Red Planet?": "B",
        "What is the largest organ in the human body?": "C",
        "What is the process by which plants make their food?": "D"
    },
    "Geography": {
        "What is the capital of France?": "A",
        "What is the largest ocean on Earth?": "B",
        "What is the tallest mountain in the world?": "C",
        "Which country is known as the Land of the Rising Sun?": "D"
    }
}
def ask_question(question, choices, answer):
    print(question)
    for choice, option in choices.items():
        print(f"{option}. {choice}")
    while True:
        user_answer = input("Enter your choice (A, B, C, or D): ").strip().upper()
        if user_answer in choices.values():
            break
        else:
            print("Invalid choice. Please enter A, B, C, or D.")
    if user_answer == answer:
        print("Correct!")
        return 1
    else:
        print("Incorrect!")
        return 0
def play_quiz(category, num_questions):
    total_score = 0
    questions = random.sample(list(quiz_questions[category].keys()), num_questions)
    for question in questions:
        total_score += ask_question(question, quiz_questions[category], quiz_questions[category][question])
    print("Quiz completed! Your score:", total_score, "/", num_questions)
def main():
    print("Welcome to the Simple Quiz Game!")
    print("Available categories:")
    for category in quiz_questions.keys():
        print("- " + category)
    category = input("Choose a category: ").strip()
    while category not in quiz_questions.keys():
        print("Invalid category. Please choose from the available categories.")
        category = input("Choose a category: ").strip()
    num_questions = int(input("How many questions would you like to answer? "))
    play_quiz(category, num_questions)
if __name__ == "__main__":
    main()
