Your First Python Project: A Quiz Game
Build a working quiz game step by step with variables, input, lists, loops, if statements and functions.
You’ve learned the core building blocks of Python: printing, variables, input, decisions, loops, lists and functions. In this final lesson you’ll combine them into a complete program, a small quiz game, and see how a real project grows one step at a time.
Type the code yourself rather than copying it. Typing it builds the muscle memory, and the mistakes you make and fix along the way are part of the learning.
Step 1: Plan before you code
Every project starts with a short plan in plain words:
QUIZ GAME PLAN
1. Store some questions and their answers
2. Ask each question in turn
3. Compare the player's answer with the correct one
4. Keep score
5. Show the final score and a message
Each line of the plan maps to something you already know: a list (1), a for loop (2), an if statement (3), a variable (4) and an f-string (5).
Step 2: Store the questions
You need questions and answers. One simple approach is two lists of the same length, where position 0 of each list belongs together:
questions = [
"What is 7 * 8?",
"What keyword defines a function in Python?",
"What index does the first list item have?",
]
answers = ["56", "def", "0"]
Answers are strings because input() returns strings, so comparing string to string is easiest.
Step 3: Ask each question
Loop through the questions with range(len(questions)), so you have an index i to look up the matching answer:
score = 0
for i in range(len(questions)):
reply = input(questions[i] + " ")
if reply == answers[i]:
print("Correct!")
score = score + 1
else:
print(f"Not quite. The answer was {answers[i]}.")
Run it now, before adding anything else. Building in small steps and running often makes errors much easier to find.
Step 4: Make answers more forgiving
If the player types DEF with spaces or capitals, the comparison fails. Two string methods fix that:
.strip()removes spaces from the start and end..lower()converts to lowercase.
Put this logic in a function so it’s easy to reuse and change:
def is_correct(reply, answer):
return reply.strip().lower() == answer.lower()
Then replace if reply == answers[i]: with if is_correct(reply, answers[i]):.
Step 5: Show a final message
After the loop, calculate a percentage and choose a message:
percent = score / len(questions) * 100
print(f"You scored {score}/{len(questions)} ({percent:.0f}%).")
if percent >= 70:
print("Great job, you passed!")
else:
print("Keep practising and try again.")
The complete program
# quiz_game.py - a small quiz game
def is_correct(reply, answer):
return reply.strip().lower() == answer.lower()
def run_quiz(questions, answers):
score = 0
for i in range(len(questions)):
reply = input(f"Q{i + 1}. {questions[i]} ")
if is_correct(reply, answers[i]):
print("Correct!\n")
score = score + 1
else:
print(f"Not quite. The answer was {answers[i]}.\n")
return score
questions = [
"What is 7 * 8?",
"What keyword defines a function in Python?",
"What index does the first list item have?",
"What does len('hello') return?",
]
answers = ["56", "def", "0", "5"]
print("Welcome to the Python quiz!\n")
score = run_quiz(questions, answers)
percent = score / len(questions) * 100
print(f"You scored {score}/{len(questions)} ({percent:.0f}%).")
if percent >= 70:
print("Great job, you passed!")
else:
print("Keep practising and try again.")
\n inside a string adds an extra blank line, which makes the output easier to read.
Ideas to extend it
Once it works, try one or more of these challenges:
- Add your own questions about a subject you’re studying. Writing quiz questions is also excellent active recall practice.
- Shuffle the order: add
import randomat the top and look uprandom.shuffle()in the official docs. (Hint: you’ll need to shuffle questions and answers together.) - Play again: wrap the game in a
whileloop that asks “Play again? (y/n)”. - Track a best score across rounds with a variable outside the loop.
When you get stuck, read the error message from the bottom up (Lesson 1), test small pieces in the interactive shell and check the official Python Tutorial.
Where to go next
- The official Python Tutorial covers dictionaries, files and error handling next.
- Practise a little every day. Short, regular sessions beat one long weekend, the same spacing idea from our Study Skills Fundamentals course.
- Test yourself with our Python basics practice quiz.
Key takeaways
- Plan in plain words first, then map each step to a Python tool you know.
- Build in small steps and run your code often.
- Functions like
is_correct()keep logic tidy and easy to change. .strip()and.lower()make text comparisons more forgiving.
That’s the whole course. Take the final quiz to check what you’ve learned and earn your free certificate of completion.
Progress is saved in this browser only.