* Program of Quiz Gme :
class Quiz:
def __init__(self, questions):
self.questions = questions
self.score = 0
def ask_question(self, question, correct_answer):
answer = input(question + " ").lower()
if answer == correct_answer:
print("Correct!\n")
self.score += 1
else:
print("Incorrect. The correct answer is:", correct_answer, "\n")
def start(self):
print("Welcome to the Quiz Game!\n")
for i, (question, answer) in enumerate(self.questions, 1):
print("Question", i)
self.ask_question(question, answer)
print("Quiz complete! Your score:", self.score, "out of", len(self.questions))
# List of questions and answers user put any question and answer.
questions = [
("What is the capital of India?", "New delhi"),
("Which planet is known as the 'Red Planet'?", "mars"),
("What is the largest mammal?", "blue whale"),
("Which country did virat kholi play for?", "India"),
("India won its first olympic hockey worldcup in?", "1928"),
("World wide web is being standard by?", "w3c"),
]
# Create a Quiz instance and start the game
quiz = Quiz(questions)
quiz.start()
OUTPUT :
Welcome to the Quiz Game!
Question 1
What is the capital of India? New delhi
Incorrect. The correct answer is: New delhi
Question 2
Which planet is known as the 'Red Planet'? mars
Correct!
Question 3
What is the largest mammal? blue whale
Correct!
Question 4
Which country did virat kholi play for? India
Incorrect. The correct answer is: India
Question 5
India won its first olympic hockey worldcup in? 1928
Correct!
Question 6
World wide web is being standard by? w3c
Correct!
Quiz complete! Your score: 4 out of 6
Copy and paste this code into a Python file and run it.
It will present the user with the questions one by one
and ask for their answers. At the end of the quiz, it will
display the user's score.
Feel free to modify the questions and answers in the questions
list, add more questions, or enhance the user interface as you see fit.
You could also add features like a timer, multiple-choice questions,
or a scoring system based on difficulty.