Building a Simple Quiz Game in
Python
Using If-Else Statements
Introduction to If-Else Statements
• If-Else statements allow decision-making in
Python.
• They execute different blocks of code based
on conditions.
Structure of If-Else in Python
• if condition:
• # Code executes if condition is True
• else:
• # Code executes if condition is False
Designing the Quiz Game
• 1. Display a question with multiple choices.
• 2. Take user input.
• 3. Use if-else to check the answer.
• 4. Display the result.
Python Code Example
• question = "What is the capital of France?\nA)
Berlin\nB) Madrid\nC) Paris\nD) Rome"
• print(question)
• answer = input("Enter your choice (A/B/C/D):
")
• if [Link]() == "c":
• print("Correct!")
• else:
• print("Wrong answer. The correct answer is
Running the Quiz Game
• 1. Run the script in a Python environment.
• 2. Enter your choice when prompted.
• 3. Receive feedback based on your answer.
Conclusion
• Using if-else statements, we built a simple quiz
game.
• You can extend it with more questions,
scoring, and difficulty levels.