Skip to course content
Free course

Python Foundations / Module 5 / Applied Checkpoint: Refactor Course-Record Cleaning

Module 5 lesson

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:

  1. clean_code(raw_code: str) -> str
  2. clean_course_name(raw_name: str) -> str
  3. clean_status(raw_status: str) -> str
  4. prepare_course_record(record: dict) -> dict
  5. format_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

CriterionNot yetMeets
ResponsibilitiesOne large function or repeated cleaning remainsEach function has one clear role
ContractInputs, outputs, or assumptions are unclearParameters, return values, docstrings, and basic hints agree
Side effectsCleaning functions print or modify source recordsFunctions return new values and preserve inputs
ReuseLogic remains copied for each recordOne set of functions handles all supplied records
Module behaviourImport prints a report unexpectedlyMain guard separates demonstration from import
BehaviourRefactored values differ from expected resultsCodes, names, statuses, summaries, and total are correct
ReproducibilityClean run or import test failsDirect run, import, and restart-and-run-all pass