Applied Checkpoint: Refactor Course-Record Cleaning
Unit ID: M05-U09 Estimated active time: 45-60 minutes
Supplied records
raw_records = [
{"code": " ai-01 ", "name": " ai foundations ", "hours": 8, "status": " AVAILABLE "},
{"code": " py-01 ", "name": " python foundations for ai ", "hours": 32, "status": " AVAILABLE "},
{"code": " ml-01 ", "name": " machine learning foundations ", "hours": 40, "status": " AVAILABLE "},
]
Required functions
Create:
clean_code(raw_code: str) -> strclean_course_name(raw_name: str) -> strclean_status(raw_status: str) -> strprepare_course_record(record: dict) -> dictformat_course_summary(record: dict) -> str
Every function requires a concise docstring. Cleaning and preparation functions must return values without printing.
prepare_course_record() must return a new dictionary and must not modify the supplied record.
Required orchestration
- Preserve a source snapshot.
- Process all three records by calling
prepare_course_record(). - Store clean records in a new list.
- Format and print one summary per clean record.
- Assert that source records remain equal to the snapshot.
- Assert the expected clean codes, statuses, and total hours.
Expected summaries:
AI-01 | AI Foundations | 8 hours | available
PY-01 | Python Foundations For AI | 32 hours | available
ML-01 | Machine Learning Foundations | 40 hours | available
Reusable module requirement
Place the functions in course_tools.py. Put direct demonstration code under a main guard so importing the module produces no report output.
Self-review rubric
| Criterion | Not yet | Meets |
|---|---|---|
| Responsibilities | One large function or repeated cleaning remains | Each function has one clear role |
| Contract | Inputs, outputs, or assumptions are unclear | Parameters, return values, docstrings, and basic hints agree |
| Side effects | Cleaning functions print or modify source records | Functions return new values and preserve inputs |
| Reuse | Logic remains copied for each record | One set of functions handles all supplied records |
| Module behaviour | Import prints a report unexpectedly | Main guard separates demonstration from import |
| Behaviour | Refactored values differ from expected results | Codes, names, statuses, summaries, and total are correct |
| Reproducibility | Clean run or import test fails | Direct run, import, and restart-and-run-all pass |
