beginner

Case File: Your First Audit

The finale brings everything together: read a file, loop, count with a dictionary, apply a rule with exact edges, write a function, and use dates. Check the delivery promise of the company: for each delivery work out the days it took (leap days and year changes included), mark it ok, late or pending, count each, find the slowest, average the finished ones, and say fail or ok. A clean audit must say ok. The deliveries are generated for you alone.

45 min

Sabi Logistics Β· Python 9

Your First Audit

The customer says that we missed our delivery promise and wants a signed statement of how many deliveries were late

Halima Operations manager Β· Phone call

Halima. A customer says that we missed our delivery promise this month and wants a signed statement of how many deliveries were late. I will not sign anything that I cannot explain. We promise delivery within a number of days of sending.

I have the date each parcel was sent and the date it was delivered (or nothing yet, if it is still on the road). Please audit it: the days each delivery took, which are ok, which are late and which are pending, how many of each, the slowest delivery, the average of the finished ones, and one word at the end: ok or fail. And if nothing is late, the audit must clearly say ok.

The brief

What you need to know first.

  • Dates are not text. "2026-10-04" is only text until you convert it: date.fromisoformat("2026-10-04") (after from datetime import date). Subtracting two dates gives a difference, and .days is its length in whole days: (date.fromisoformat(b) - date.fromisoformat(a)).days. Python knows about months, years and leap days, so you never count by hand: 2028-02-28 to 2028-03-01 is 2 days, and 2026-12-31 to 2027-01-03 is 3.
  • Three statuses. A delivery whose delivered is None is pending: it is neither ok nor late yet, and its days is None. Otherwise days is the days between sent and delivered, and the status is late when days is more than sla_days (exactly the SLA is ok), else ok.
  • The audit result. rows (id, days, status in order), counts (how many of each status that occurs), worst_id (the id with the most days among the finished ones, the first on a tie, None if none finished), mean_days (the average days of the finished ones, 3 decimals, 0 if none), and status: "fail" if any delivery is late, otherwise "ok".
  • A clean audit must say ok. A report that can only report problems is not an audit: an empty file, or one without late deliveries, gives the status "ok", with the counts that were found.
  • Fill in days_between, audit(req), then result and n_pending. The checks run audit on files that you cannot see: a clean one, one with a leap day, a year change and a pending delivery, and an empty one.

The lab gives you the data for this case, invented and generated for you alone.

Preparing your data…

πŸ”’ The debrief unlocks when you close the case. Finish the lab above.

Write the first audit note

Write the statement for the operations manager and the customer: the rule you checked (the delivery promise in days, exactly the promise is ok), how many deliveries were examined, how many were ok, late and pending, the slowest delivery and the average days of the finished ones, the overall status, what the pending deliveries mean (not yet known, to be rechecked), the date of the report, and what you can honestly sign.

0 words

πŸ§ͺ Want to practise this on your own computer? See how to set up your lab →

πŸ€–

Need clarification? Ask GT

Hi, I'm GT β€” your AI tutor for Case File: Your First Audit. What would you like to know?
πŸ“

Knowledge Check

1 of 3

How many days are there from 2028-02-28 to 2028-03-01?

βš‘ Capture The Flag

Report a problem

About: /lessons/case-the-first-audit