class TriviaGame:
    def __init__(self, questions):
        self.questions = questions
        self.score = 0

    def play_game(self):
        print("Welcome to the Trivia Game!")
        for question, options, correct_option in self.questions:
            print(question)
            for i, option in enumerate(options, 1):
                print(f"{i}. {option}")

            user_answer = int(input("Your answer (enter the option number): "))

            if user_answer == correct_option:
                print("Correct! ")
                self.score += 1
            else:
                print(f"Wrong! The correct answer was {correct_option}. ")

        print(f"Game over! Your final score is {self.score}/{len(self.questions)}.")

if __name__ == "__main__":
    # Sample trivia questions (replace with your own)
    trivia_questions = [
        ("What is the capital of France?", ["Berlin", "Madrid", "Paris"], 3),
        ("Which planet is known as the Red Planet?", ["Earth", "Mars", "Venus"], 2),
        # Add more questions here
    ]

    # Create an instance of the TriviaGame
    trivia_game = TriviaGame(trivia_questions)

    # Start the game
    trivia_game.play_game()

Post a Comment

0 Comments