Untitled

mail@pastecode.io avatarunknown
plain_text
10 days ago
2.2 kB
4
Indexable
Never
import random

# Define multiple sets of trivia questions and answers
question_sets = [
    [
        "What is the capital of France?",
        "A) London\nB) Berlin\nC) Paris",
        "C"
    ],
    [
        "What is the largest planet in our solar system?",
        "A) Venus\nB) Mars\nC) Jupiter",
        "C"
    ],
    [
        "Which gas do plants absorb from the atmosphere?",
        "A) Oxygen\nB) Carbon dioxide\nC) Nitrogen",
        "B"
    ]
]

# Define another set of trivia questions and answers
question_set_2 = [
    [
        "What is the largest mammal on Earth?",
        "A) Elephant\nB) Blue Whale\nC) Giraffe",
        "B"
    ],
    [
        "Which planet is known as the Red Planet?",
        "A) Venus\nB) Mars\nC) Jupiter",
        "B"
    ],
    [
        "What is the chemical symbol for water?",
        "A) H2O\nB) CO2\nC) O2",
        "A"
    ]
]

def ask_question(question_set):
    question, choices, correct_answer = question_set
    print(question)
    print(choices)

    user_answer = input("Your answer (A/B/C): ").strip().upper()

    if user_answer == correct_answer:
        print("Correct!\n")
        return 1
    else:
        print(f"Wrong! The correct answer is {correct_answer}.\n")
        return 0

def main():
    print("Welcome to the Trivia Game!")

    while True:
        # Ask the user which set of questions to use
        print("Choose a question set:")
        print("1. Set 1")
        print("2. Set 2")

        try:
            set_choice = int(input())
            if set_choice in [1, 2]:
                break
            else:
                print("Invalid choice. Please select a valid set.")
        except ValueError:
            print("Invalid input. Please enter a number.")

    # Shuffle the chosen question set
    if set_choice == 1:
        selected_set = random.sample(question_sets, 3)
    else:
        selected_set = random.sample(question_set_2, 3)

    score = 0

    # Ask three questions from the selected set
    for question in selected_set:
        score += ask_question(question)

    print(f"Game over! Your score is {score}/3.")

if __name__ == "__main__":
    main()