Plan, Build, and Test Programs · capstone
Capstone project: Project: Prepare Your Quiz Engine
The quiz engine has been our workbench throughout this chapter. Chapter 12 turns it into the final capstone, with a subject you choose. Before building the interactive
This is how a larger project becomes manageable. You are not “building a quiz engine” all at once. You are completing a tested blueprint with clear boundaries, one piece at a time.
Write the brief
The final program will:
store a quiz title and at least three question records;
ask each question;
compare answers while ignoring capitalization and surrounding spaces;
track and report the score;
reject an empty answer and ask that question again;
finish cleanly after the final question.
This chapter prepares the stored plan, the answer-comparison helpers, and a readiness check. Chapter 12 adds asking questions, tracking the score, and the final report.
Model one question
Each question record has the same required keys:
{
"prompt": "Which material do bees make?",
"answer": "honey",
}
The prompt is what the learner sees. The answer is the
Store the records in a
quiz_plan = {
"title": "A Subject You Choose",
"questions": [
# consistently shaped question dictionaries
],
}
This structure can move directly into the final project.
State the answer rule once
The comparison rule is:
Ignore capitalization and surrounding whitespace, but otherwise require the complete answer to match.
Put cleaning in one
Test both paths:
differently capitalized and padded versions of the same answer match;
a genuinely different answer does not match.
Validate the plan itself
A blueprint is ready only when:
its title is not empty;
it has at least three questions;
every question has a non-empty prompt and answer;
prompts are unique after cleaning.
A plan_is_ready(plan) function can check those requirements before the interactive program relies on the data.
For this check, assume the outer plan already has a "title" and a "questions" list of dictionaries, and that any present prompt and answer values are strings. Check the stated content and record-shape rules within that boundary.
This is validation of developer-authored data, not live user input. Returning True or False is sufficient here. Chapter 12 will use a retry loop for the person taking the quiz.
Preserve your own subject
Choose a subject you can write accurate questions about. It might be music, gardening, geography, crafts, sport, history, cooking, films, science, or something else.
The grader checks the structure and behavior, not one prescribed subject. Your questions and answers should be meaningful and distinct.
When this lesson passes, keep the blueprint. The first Chapter 12 milestone will ask you to bring its quiz_plan, clean_answer, and answers_match into the persistent capstone workspace.
Which part belongs in this blueprint milestone rather than the later interactive quiz loop?
What should answers_match(" PACIFIC ", "pacific") return under the planned rule?
Task
Prepare a personalized quiz-engine blueprint.
Replace the placeholder title and all three placeholder question records with a subject and accurate questions of your own. You may add more questions.
Implement
clean_answer(text)to strip surrounding whitespace and ignore capitalization.Implement
answers_match(given, expected)usingclean_answer.Implement
plan_is_ready(plan)using this contract:non-empty title;
at least three questions;
every question has exactly the required
"prompt"and"answer"fields with non-empty text;prompts are unique after cleaning.
Keep the prepared assertions and blueprint summary.
Your exact title and questions are your choice. The final output must have this shape:
QUIZ BLUEPRINT
Title: your chosen title
Questions: 3
Answer checks passed.
The number may be greater than 3 if you add more questions.