──────────────────────────────────────

40. Pocket Quiz Capstone · Build and Share Pocket Quiz

Deliver a three-question quiz with a score, input handling and explained test evidence.

Lesson files · lessons/foundations-capstone/pocket-quiz

Before you start
- Loop over a list of dictionary records.
- Use a function to check one reply against an answer key.
- Keep a score across a loop and print it after the loop.

By the end
- Use a record to keep each prompt together with its answer key.
- Use the same matching function for each question.
- Test that a blank reply still lets the next question run.

Where you can use it
Make a revision quiz for a classmate. Keep the prompts with their answer keys and test a blank reply before sharing the quiz.

Keep each prompt and its lowercase answer key in the same dictionary. Loop over the list of question records and print one prompt at a time. Read one line after each prompt, even when that line is blank.

Reuse is_correct from the earlier activity to check the reply against that record's answer. A play_round function can return the final score after printing prompts and scoring each reply. Build the score label from the score and the number of questions.

Predict
Where should you edit a question and its answer together?
- Inside the score counter.
- In its dictionary record.

Worked example (example.py)

question = {"prompt": "Name the red planet.", "answer": "mars"}
print(question["prompt"])


Example result
Name the red planet.

Use the three starter records. Print each prompt, read one answer, and use the same helper function to check each cleaned reply. Award one point per match. Treat blank answers as wrong and continue to the next question. Print Score: points/3 on the final line, using the points earned.

Record the input and result from a normal test and a blank-answer test. In your reflection, explain one decision you made.

Starter program (starter.py)

questions = [
    {"prompt": "Name the red planet.", "answer": "mars"},
    {"prompt": "What is 2 + 2?", "answer": "4"},
    {"prompt": "Which animal says moo?", "answer": "cow"},
]
for question in questions:
    print(question["prompt"])
    input()
print("Score: 0/3")


Starter input
Mars
4
cow

Hint
Pass the record’s answer to is_correct and add to a shared score on each match.

Case 1. Try the sample
Input
 Mars 
4
COW
Expected output
Name the red planet.
What is 2 + 2?
Which animal says moo?
Score: 3/3

Case 2. Blank answer in the middle
Input
mars

cow
Expected output
Name the red planet.
What is 2 + 2?
Which animal says moo?
Score: 2/3

Case 3. No correct answers
Input
venus
7
cat
Expected output
Name the red planet.
What is 2 + 2?
Which animal says moo?
Score: 0/3

Project checklist
Run the sample case.

Project checklist
Try one different case and explain what happened.

Marking criterion
Program behaviour (4 points)
Each required behaviour works on the supplied cases.

Marking criterion
Use of the lesson concept (3 points)
The code uses the main idea in a clear, purposeful way.

Marking criterion
Test evidence (2 points)
The reflection describes a case, its expected result and what happened.

Marking criterion
Explanation (1 points)
The learner explains a change or design decision in their own words.

Stretch
Use your own three-question topic and ask someone to play. Keep a before-and-after list of improvements.

Reflect
Explain what is_correct returns and what would happen in a round with one blank answer.

Check your prediction
In its dictionary record. A record groups the two fields for the same question.
