Applied PythonLesson 19 of 1925 min
Capstone: Build a Quiz App
Put variables, loops, dicts, functions, classes, and error handling together into one working program.
By the end you will be able to
- Combine the whole course into a single program
- Structure code as small, testable functions
- Handle bad input without crashing
Time to build something end to end: a quiz engine that stores questions, scores answers, tracks results, and reports a summary.
Everything it uses has appeared earlier in the course. Read each stage, run it, then tackle the exercises at the bottom.
Stage 1 — the data
Questions are a list of dicts. Keeping data separate from logic means adding a question never requires touching the code that scores one.
1. What does len('Python') return? [strings]
2. Which operator gives the remainder? [operators]
3. What type does 3 / 2 produce? [numbers]
— expected output; press Run to execute it yourselfStage 2 — scoring one question
One small function, one job. Easy to reason about and easy to test.
True
False
Rejected: choice must be 0..2
— expected output; press Run to execute it yourselfStage 3 — the full engine as a class
The class holds the questions and the running results together, and reports on them.
Q1: correct
Q2: wrong
Q3: correct
Q4: wrong
Score: 2/4 (50%) — REVIEW
revise operators (1 missed)
revise types (1 missed)
— expected output; press Run to execute it yourselfExercise
Write grade(score, total) that returns "A" for 90%+, "B" for 80%+, "C" for 70%+, "D" for 60%+, and "F" below that. Return "F" if total is 0 rather than crashing.
Press Run to execute this code.
Exercise
Write summarise(results) where results is a list of (topic, correct) tuples. Return a dict mapping each topic to its percentage correct, rounded to the nearest whole number. Example: [("a", True), ("a", False), ("b", True)] → {"a": 50, "b": 100}.
Press Run to execute this code.
Where to go next
You now have the whole core of the language. Natural next steps:
- Practise — rebuild the quiz app from a blank file without looking. Recall beats rereading.
- Virtual environments and pip —
python -m venv .venvthenpip installto use third-party packages. - Pick a direction —
requestsandFastAPIfor web,pandasfor data,pytestfor testing. - Write tests — the
testsbehind every exercise on this site are ordinaryassertstatements. That is genuinely how testing starts.