← Course Home
Module 13 · Tier 5

Modular User Audit Script

The moment a one-off script becomes a reusable tool. Ten labs on Module 7 — rebuilding Tier 4's account-finder as a proper fetch → analyze → report function chain, over the same real fixture.

Lab 1

The Fetch Function

Write fetch_users() that takes no parameters and returns USERS. Call it, print type() of the result, then its len().

<class 'list'> then 12
Lab 2

A Check Function

Write is_suspended(user) that returns True if user["status"] == "SUSPENDED". Call it on USERS[2] (Bina), then USERS[0] (Julio).

True then False
Lab 3

Another Check Function

Write has_zero_groups(user) that returns True if len(user["groups"]) == 0. Call it on USERS[3] (Dana), then USERS[0] (Julio).

True then False
Lab 4

Combine Two Functions

Write is_flagged(user) that returns is_suspended(user) or has_zero_groups(user) — a function calling functions. Call it on USERS[2] (Bina), USERS[3] (Dana), USERS[0] (Julio).

True, True, False
Lab 5

The Analyze Function

Write filter_flagged(users) that loops users and returns a list of every one where is_flagged(u) is True. Call it on fetch_users()'s result. Print len(), then a list of just their first names.

5 then ['Bina', 'Dana', 'Tri', 'Rosa', 'Pat']
Lab 6

A Small Utility Function

Write get_department_safe(user) that returns user["profile"].get("department", "Unknown"). Call it on USERS[7] (Layla), then USERS[0] (Julio).

Unknown then IT
Lab 7

Build a Value, Don't Print It

Write build_report_line(user) that RETURNS (doesn't print) the string "FIRST LAST -- STATUS -- DEPARTMENT", using get_department_safe() internally. Call it on USERS[2] (Bina) and print the result yourself.

Bina Patel -- SUSPENDED -- Sales
Lab 8

The Report Function

Write print_report(flagged_users) that loops and prints build_report_line(u) for each — a side-effect-only function, no return. Call it on filter_flagged(fetch_users()), then print what print_report itself returned.

→ 5 report lines, then None — confirms it's a pure side-effect function
Lab 9

Scope Check

Write a function that creates a local variable and returns it. Call it and print the result. Then try to print that same variable name OUTSIDE the function — confirm it crashes.

→ your returned value, then crashesNameError
Lab 10 · Capstone

The Full Chain

Write main() that calls fetch_users()filter_flagged() → prints "Flagged accounts: N"print_report(), reusing every function from Labs 1-9. Call main().


Flagged accounts: 5
Bina Patel -- SUSPENDED -- Sales
Dana Morris -- ACTIVE -- IT
Tri Nguyen -- DEPROVISIONED -- Sales
Rosa Gomez -- SUSPENDED -- IT
Pat Hogan -- DEPROVISIONED -- Sales
Now go practice

Open problems/tier05_modular_audit.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.

Tier 5 complete

Tiers 1-5 done

fetch_users() → is_suspended() → has_zero_groups() → is_flagged() combining checks → filter_flagged() analyzing → get_department_safe() → build_report_line() returning a value → print_report() as a side effect → scope → the full fetch → analyze → report chain.

← Back to Module 13