The most common real-world script task: someone left, you inherited their script, and it's subtly wrong. Ten labs on Module 8 — diagnosing and fixing four real bug categories in a version of Tier 5's own script.
You're handed filter_flagged_broken(users) — it builds a flagged list correctly but never returns it. Call len(filter_flagged_broken(USERS)). Predict, then run.
TypeError: object of type 'NoneType' has no len()You're handed count_by_status_broken(users) — it uses counts[u["status"]] += 1 instead of a guarded pattern. Call it on USERS. Predict, then run.
KeyError on the first status it seesYou're handed is_flagged_broken(user) — it checks is_suspended(user) and has_zero_groups(user) instead of or. Build the flagged-names list with it over USERS. Predict, then run.
[] — no crash, just silently wrong. The real answer has 5 flagged accounts; and instead of or means almost nothing ever matches both conditions at once.You're handed build_report_line_broken(user) — it accesses user["profile"]["department"] directly instead of guarding it. Loop all USERS calling it. Predict how many lines print before it crashes, then run.
KeyError: 'department' on LaylaFix filter_flagged_broken by adding the missing return flagged. Confirm len() of the result now.
5Fix count_by_status_broken to use counts[status] = counts.get(status, 0) + 1. Call it on USERS.
{'ACTIVE': 8, 'SUSPENDED': 2, 'DEPROVISIONED': 2}Fix is_flagged_broken by changing and to or. Rebuild the flagged-names list.
['Bina', 'Dana', 'Tri', 'Rosa', 'Pat']Fix build_report_line_broken by using .get("department", "Unknown"). Call it on USERS[7] (Layla) — confirm no crash.
Layla Haddad -- ACTIVE -- UnknownOf the four bugs, three crash loudly (1, 2, 4) and one fails silently (3). Print one sentence: why is bug 3 the most dangerous of the four, even though it's the only one that never crashes?
Combine all four fixes into one clean script: fetch_users() → filter_flagged() (fixed) → print_report() using build_report_line() (fixed) — the same shape as Tier 5's capstone, now defensively written from the start. Run it.
Flagged accounts: 5Bina Patel -- SUSPENDED -- SalesDana Morris -- ACTIVE -- ITTri Nguyen -- DEPROVISIONED -- SalesRosa Gomez -- SUSPENDED -- ITPat Hogan -- DEPROVISIONED -- Sales
Open problems/tier06_inherit_and_fix.py and do all 10 problems locally. Uses fixture.py -- type it in first from DAY1_01_FIXTURE.md if it's not already in this folder. Run python check.py in problems/ to grade everything.