A small tool someone else could extend
Write a small tool that turns a list of records into a fixed-width text report: a header, one line per record, and a totals line at the bottom. Amounts align on the decimal point; names longer than the column are truncated with an ellipsis. The brief is deliberately mundane. What is being marked is whether the logic is in functions that return strings — which is what makes it testable — rather than in a script that prints as it goes.
What you have to hand in
- A header, aligned record lines, and a totals line.
- Amounts aligned on the decimal point to two places.
- Over-long names truncated rather than breaking the alignment.
- The formatting logic returns strings; printing happens in one place.
- Sensible behaviour on an empty list of records, stated rather than accidental.
The checklist, published before you start
- It does what the brief asked
Every behaviour named in the brief is present and works as described.
- Core behaviour is missing or does something else.
- Main path works; a stated requirement is unmet.
- Every stated requirement is met.
- Every requirement met, and the boundaries of each are stated.
- The pieces are testable
Logic lives in functions that return values, rather than in a script body that prints as it goes.
- One top-level script; nothing can be called in isolation.
- Some functions, but the important logic still prints rather than returns.
- Logic in functions that return their results.
- Functions with clear signatures, and the I/O confined to one place.
- It behaves sensibly on bad input
The tool's response to input it cannot handle is a decision, not an accident.
- Crashes with an unhandled traceback on ordinary bad input.
- Catches failures broadly, hiding what went wrong.
- Handles the specific anticipated failures and lets the rest surface.
- Handles them, and the message tells the user what to do next.
- A colleague could extend it
Names and structure make the next change obvious.
- Opaque names, no structure.
- Readable in places.
- Clear throughout.
- The shape of the code suggests where a new feature would go.
The skills a pass would prove
- Defining functionsWrite a function with a clear signature that returns its result rather than printing it
- Strings and formattingBuild and take apart strings without reaching for a loop where a method exists
- Raising and handling exceptionsHandle a specific failure without hiding the failures you did not anticipate
- ComprehensionsRewrite a build-a-list loop as a comprehension, and say when you would not
This brief is part of the Python Fundamentals course
Starting it starts the course: every skill above, in the order they depend on each other, with this brief at the end as the thing you hand in — marked against the checklist you have just read and nothing else.
Start the Python Fundamentals course