Project Overview
Weβre building a Python Quiz Game! This project will teach you how to:
- Print messages to the screen
- Use
input()
for interaction - Track scores with variables
- Use
if/else
to check answers
Step 1: Greeting the Player
print("π Welcome to the Python Quiz Game! π")
name = input("What's your name? ")
print("Hello " + name + "! Let's test your knowledge.\n")
This welcomes the player and asks for their name.
Step 2: Asking Questions
score = 0
print("1) What does CPU stand for?")
print("a) Central Processing Unit")
print("b) Computer Personal Unit")
print("c) Central Print Utility")
answer = input("Your answer: ").lower()
if answer == "a":
print("β
Correct!\n")
score += 1
else:
print("β Incorrect. The answer is a) Central Processing Unit.\n")
Notice how we use if/else
to check the answer.
Step 3: Add More Questions
Repeat the structure above for more questions. Hereβs another example:
print("2) Which programming language is known for the snake logo?")
print("a) Java")
print("b) Python")
print("c) C++")
answer = input("Your answer: ").lower()
if answer == "b":
print("β
Correct!\n")
score += 1
else:
print("β Incorrect. The answer is b) Python.\n")
Step 4: Show the Score
print("π― You scored " + str(score) + " out of 2.")
if score == 2:
print("π Excellent job, " + name + "!")
elif score == 1:
print("π Good work, " + name + "!")
else:
print("π‘ Keep practicing, " + name + "! You'll get it next time.")
This shows the playerβs final score and gives feedback.
Mini Challenge
π― Add a 3rd or 4th question of your own! Be creative β ask about technology, favorite foods, or fun facts.
Wrap-Up
Youβve built a working Python quiz game! You now know how to:
- Print and format text
- Get user input
- Use
if/else
logic - Track a score
Keep customizing your quiz for practice!