Chapter 12 · practice
Final Capstone: Build a Quiz Engine
Bring Your Blueprint into the Workspace
This chapter is different from the earlier ones. You are building one program across several lessons.
The editor now owns main.py inside a persistent chapter workspace. When you complete a milestone, your working
Start from your Chapter 11 blueprint
Your blueprint contained:
a quiz title;
at least three question
; clean_answer(text);answers_match(given, expected);a readiness check for the plan.
Bring those decisions forward instead of choosing a new subject.
There is one small structural change. Store the plan inside a function:
def build_quiz_plan():
return {
"title": "Nature Quiz",
"questions": [
{
"prompt": "Which animal builds a dam?",
"answer": "beaver",
},
],
}
The example is deliberately small; your function keeps the complete personalized plan from Chapter 11. The important idea is that it can rebuild and return that data whenever the program starts.
Why put the data in a function?
The workspace carries completed top-level function definitions into each new milestone. Keeping the personalized data inside build_quiz_plan() means your chosen title, questions, and answers travel with that definition.
The function gives the rest of the program a clear starting call:
plan = build_quiz_plan()
The caller does not need to know how the records were written.
Keep one consistent question shape
Every question must contain exactly:
{
"prompt": "Question shown to the player",
"answer": "Expected answer",
}
Consistency lets later functions use the same two keys for every record.
Validate developer-authored data
plan_is_ready(plan) protects the later milestones from an incomplete blueprint. It should reject:
an empty title;
fewer than three questions;
a record with missing, extra, or empty fields;
prompts that become duplicates after cleaning.
Assume the outer plan has a "title" and a "questions"
This function validates the data you authored. It is separate from the live-answer validation you will build later.
A persistent project changes the rhythm
Before submitting:
run the focused assertions;
confirm your own title and questions are still present;
submit the complete
main.py;continue only after the milestone passes.
Reset restores the milestone code supplied when you opened this lesson, including earlier functions carried forward into it. This discards edits made since that starting point. Resetting the entire chapter workspace clears the accumulated project files and restores the chapter’s starting files, while passed lessons remain completed. Use that larger reset only when you want to rebuild the project.
What does calling build_quiz_plan() give the rest of the program?
Task
Bring your Chapter 11 blueprint into main.py.
Replace the placeholder title and question records inside
build_quiz_plan()with your chosen subject and at least three accurate questions.Implement
clean_answer(text)so it strips surrounding whitespace and ignores capitalization.Implement
answers_match(given, expected)usingclean_answer.Implement
plan_is_ready(plan)with the complete readiness contract from the lesson.Keep the prepared assertions.
If your Chapter 11 blueprint is open in another tab, copy its title and question records rather than inventing a second quiz.