──────────────────────────────────────

72. Make Your Own Python Tool · Independent Capstone · Ship Your Python Tool

Deliver a Python tool for a chosen user, test it on unfamiliar input, and demonstrate a change after feedback.

Lesson files · lessons/make-your-own-tool/independent-tool

Before you start
- Build a CLI that summarises and validates a CSV export.
- Check a preview, an exclusive write and an unfamiliar dataset.
- Describe how to run a program for someone new to it.

By the end
- Deliver a command-line tool that fulfils the chosen brief and passes the supplied cases.
- Demonstrate its output on someone else’s export and record their run-guide feedback.
- Add and test one requested option, then rerun the original cases.

Where you can use it
Build a report a desk volunteer can run on their own exports, then use their first run to choose and verify an improvement.

Choose one brief. A seed exchange needs crop totals to flag low stock. A book donation desk needs category totals to prepare boxes. A club kit desk needs equipment totals to spot shortages. The offline workbook has a fictional export for each. You can agree on another local task that uses the same input and output rules.

Plan time for a first working version, a handover and a revision. Start with one expected result you can calculate by hand. Use the earlier labs and language reference when you get stuck. Keep a note of one bug, the input that exposed it and the result after you fixed it.

Predict
Your script works on your own CSV. What should you do before handing it over?
- Rename your existing input and run the same rows again.
- Test a new file and ask someone to run it from the guide.

Worked example (example.py)

accepted, invalid, repeated = 3, 1, 1
print(f"Read: {accepted + invalid + repeated}")
print(f"Useful: {accepted}")


Example result
Read: 5
Useful: 3

Write the tool from the chosen brief and the checklist. In Studio, read CSV from Program input and match the practice cases. Then verify the local command with a CSV path, --threshold and --output.

Give someone the script and your run guide. Ask them to bring an unfamiliar CSV, predict what it should report and run it using the guide. Record the command, the expected result, what they saw and one change they ask for.

Write a case for the requested change before you implement it. After adding the new option, show the new case and rerun the original commands.

Starter program (starter.py)

# Put the tool name and a short run guide here.
# Sketch the steps for reading, validating and reporting.
print("Tool in progress")


Starter input
id,category,quantity
S1,Beans,6
S2,Maize,0
S3,Beans,1
S1,Beans,6
S4,Maize,oops

Hint
Compare your report for one ordinary row and a header-only export with your predictions. Use the first difference to decide what to investigate.

Case 1. Try the sample
Input
id,category,quantity
S1,Beans,6
S2,Maize,0
S3,Beans,1
S1,Beans,6
S4,Maize,oops
Expected output
Totals
Beans: 7
Maize: 0
Accepted: 3
Invalid: 1
Duplicates: 1

Case 2. Different groups and a corrected row
Input
quantity,id,category
2,L1,Comics
3,L2,Science
-1,L3,History
0,L3,History
Expected output
Totals
Comics: 2
History: 0
Science: 3
Accepted: 3
Invalid: 1
Duplicates: 0

Case 3. Header only
Input
id,category,quantity
Expected output
Totals
Accepted: 0
Invalid: 0
Duplicates: 0

Project requirement
Choose a user and a brief from the lesson. Record the decision the report will help them make.

Project requirement
Read CSV with headers id, category and quantity in any order. Report a missing, duplicate or unexpected header with “Error: expected columns id,category,quantity.”

Project requirement
Strip spaces around ID and category. Reject blank IDs, blank categories, extra fields and missing, negative or non-integer quantities. Accept zero. Keep the first valid row for each ID.

Project requirement
Print Totals, then one Category: N line per category in alphabetical order. Follow the lines with Accepted, Invalid and Duplicates counts in that order.

Project requirement
Run from a local command with a CSV path. For --threshold N, add Below threshold: and a sorted, comma-separated list of categories whose total is below N, or none. Preview on screen by default and create a new report only with --output.

Project requirement
Share run instructions, one sample CSV, and tests for ordinary data, an empty export, malformed data and a repeat write.

Project requirement
After the handover, implement one new requirement as its own option and test that behaviour. For example, support a JSON report for a book intake tool or let kit staff show one chosen category. Preserve the results of the original cases.

Project checklist
I recorded the goal and the person who will use my tool.

Project checklist
I tested a file someone else supplied, a header-only file and a bad input.

Project checklist
I checked the preview, threshold and protection against overwriting a previous report.

Project checklist
Someone tried my run guide. I added a test and a new behaviour based on their feedback.

Marking criterion
Useful working tool (4 points)
The chosen user can run it. It reports correct totals and separates accepted, invalid and duplicate rows on an unfamiliar CSV.

Marking criterion
Reliable handling (3 points)
It handles a quiet week and a broken input, preserves the original input and an existing report, and previews and applies a threshold correctly.

Marking criterion
Test evidence (2 points)
The learner recorded predictions and results for several cases, including a file they did not write, and can rerun the checks.

Marking criterion
Handover and revision (1 points)
A second person can run the tool from the guide. The learner explains one decision and demonstrates new behaviour with a test after feedback.

Stretch
Run against wrong-header.csv from the workbook. Then make a copy of a valid CSV and add a row with an extra field and an ID you have already used. Check the error for the header and the row counts for the edited file.

The ZIP includes added practice files for this lesson. Open its lesson folder and read the included instructions.

Reflect
What did you learn from another person running the tool? Name the change you made and show the evidence it still works.

Check your prediction
Test a new file and ask someone to run it from the guide. New data and a new reader reveal assumptions hidden by the first example.
