Skip to content

Building a Small Project: Quiz Game

Programming Python Difficulty 1/5

Beginning of the lesson

Building a Small Project: Quiz Game

Put variables, loops, conditions and functions together to build a real game

Big Idea: Everything you have learned so far is a building block. In this topic we put them together, one step at a time, to build a complete quiz game: the computer asks questions, reads your answers, keeps a score, and tells you how you did. That is real programming!
By the end you will be able to:
  • ask a question and check the answer with input() and if,
  • keep a running score in a variable,
  • wrap the "ask one question" idea in a function that returns points,
  • use a for loop and a list to run the whole quiz.

1. The plan: input -> process -> output

A quiz game is just a loop of a very simple idea. For each question the computer does three things: ask (show the question and read your answer), check (is the answer correct?), and update (add a point if it was right). After all the questions, it shows your final score.

Think of a friendly game-show host with a stack of cards. They read a card, listen to your answer, tick a box if you are right, then reach for the next card. When the cards run out, they announce your score. Our program is that host.

Ask a question input() Check the answer if / else Update the score score + 1 Show the final score
For every question: ask, check, and update the score. When the questions run out, show the final score.
A big program is just small, familiar steps repeated in a loop. Build one step, test it, then add the next.

2. Step 1: one question with input and if

Let us start with the smallest possible quiz: a single question. input() shows a message and waits for the person to type. It always hands back what they typed as text (a string). We then compare that text with the correct answer using ==.

answer = input("What is 2 + 2? ")
if answer == "4":
    print("Correct!")
else:
    print("Wrong.")

Sample run (the person types 4):

What is 2 + 2? 4
Correct!

Because input() gives back text, we compare with the text "4" in quotes, not the number 4. The if line ends with a colon, and the lines that belong to it are indented.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers