0%

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 remain in that file. The next lesson adds a new function for you to build without replacing the functions you already finished.

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" of dictionaries. Any present prompt and answer values are strings. Check the content and record-shape rules above; this is not a validator for every possible Python .

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:

  1. run the focused assertions;

  2. confirm your own title and questions are still present;

  3. submit the complete main.py;

  4. 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.

  1. Replace the placeholder title and question records inside build_quiz_plan() with your chosen subject and at least three accurate questions.

  2. Implement clean_answer(text) so it strips surrounding whitespace and ignores capitalization.

  3. Implement answers_match(given, expected) using clean_answer.

  4. Implement plan_is_ready(plan) with the complete readiness contract from the lesson.

  5. 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.