import random

# Define some quiz questions with multiple-choice answers
questions = [
    {"question": "What is the capital of France?", "choices": ["Paris", "London", "Berlin"], "answer": 0},
    {"question": "2 + 2 =", "choices": ["2", "4", "8"], "answer": 1},
    {"question": "What is the largest planet in our solar system?", "choices": ["Earth", "Jupiter", "Mars"], "answer": 1}
]

# Function to display a question and answer choices
def display_question(question):
  print(question["question"])
  for i, choice in enumerate(question["choices"]):
    print(f"{i+1}. {choice}")

# Function to check the player's answer
def check_answer(question, answer):
  correct_answer = question["answer"]
  return answer == correct_answer

def main():
  # Welcome message
  print("Welcome to the Quiz Game!")

  # Set the number of questions per game
  num_questions = 3

  # Randomly select questions
  random_questions = random.sample(questions, num_questions)

  # Initialize score
  score = 0

  # Loop through each question
  for question in random_questions:
    display_question(question)
    user_answer = int(input("Enter your answer (1, 2, or 3): ")) - 1

    if check_answer(question, user_answer):
      print("Correct!")
      score += 1
    else:
      print("Incorrect. The correct answer is", question["choices"][question["answer"]])

  # Display final score
  print(f"You scored {score} out of {num_questions} questions.")

if __name__ == "__main__":
  main()
