←Previous page

12GAME PROJECTS · QUIZ

Make your own quiz.

Build a game that asks questions, checks the answers, and counts your points.

IN REAL LIFE

Questions with points.

Ask, answer, check, count. Quizzes are everywhere.

TV game shows

The host reads a question, checks your answer, and adds points.

Class quiz apps

Everyone answers on a screen, and the app shows the score at the end.

Flash cards

A question on the front, the answer on the back. You count how many you got.

THE PLAN

Four small steps.

Each step uses something you already learned.

Two lists

One list keeps the questions, the other the answers, in the same order.

[ ] questions[i]

Ask each one

A for loop goes through every question and asks it with input().

for range() input()

Check and count

lower() ignores capitals. If the answer matches, add 1 to the score.

if lower() + 1

Final message

After the loop, if and elif pick a message for the score.

if elif else

RUN IT

Play the quiz.

Guess first. Then run real Python and check.

1

Guess the result

Read the game in the editor. Then look at PyBot's answers.

PyBot's answers: 5, Blue, cusco

What score does Python show?

quiz.pyREAL PYTHON
OUTPUT
Ready. Press Run Python.
Python runs here thanks to Pyodide ♥

Pyodide 314.0.3 runs CPython in your browser with WebAssembly.

Open-source under the Mozilla Public License 2.0. License

Now change one thing: Write your own question and answer at the end of each list, then change range(3) to range(4).

BUILD IT

Build the quiz, piece by piece.

Each task builds one part of a quiz. Match the goal.

0Completed
11Not tried
0Review
01

Step 1: capitals are OK

The player typed BLUE and lost the point. Use lower() so capitals do not matter.

Goal output
What color is the sky? BLUE
Correct!
OUTPUT

02

Step 2: keep score

Both answers are right, but the score stays 0. Add the missing line.

Goal output
2 + 2? 4
Correct!
3 + 3? 6
Correct!
Score: 2
OUTPUT

03

Step 3: the final message

Follow the comments. Add an elif and an else so 1 point shows the right message.

Goal output
Good try!
OUTPUT

YOUR TURN

Questions about the quiz.

Try each tiny question. A wrong answer becomes something to review.

04

Which question?

questions = ["2 + 3?", "Sky color?", "Capital of Peru?"] print(questions[1])

What will Python show?

05

Same order

questions = ["2 + 3?", "Sky color?"] answers = ["blue", "5"]

A player answers 5 to "2 + 3?". What happens?

06

How many turns?

for i in range(3): print(i)

Which numbers does i take?

07

Small letters

reply = "LiMa" print(reply.lower())

What will Python show?

08

A sneaky capital

answers = ["Lima"] reply = "lima" if reply.lower() == answers[0]: print("Correct!") else: print("Oops!")

What will Python show?

09

Count the points

The quiz has 3 questions. The player gets 1 right and 2 wrong.

score = 0 ... score = score + 1

What is the score at the end?

10

The final message

score = 0 if score == 3: print("Perfect! You are a quiz star.") elif score == 2: print("Great job!") else: print("Keep practicing!")

What will Python show?

Your work is saved here.

Want a fresh start? Clear only this page.

!
BIG IDEA

Lists + a loop = a whole quiz.

Keep questions and answers in lists, ask each one with for, and let the score decide the final message.