beginner

Case File: Late, Very Late, or On Time

Customer service wants every delivery marked on time, late or very late, with a count of each and the worst case. The rule sounds simple and is all edges: exactly on the promised day, late by one, late by three. Learn if and else, comparison operators, and the habit of testing the exact limits, which is where most beginner bugs hide. The deliveries are generated for you alone.

45 min

Sabi Logistics · Python 4

Late, Very Late, or On Time

The monthly report said that fifteen parcels were very late, the manager counted twelve, and neither knows which three are different

Emeka Support engineer ·

Emeka. Customer service marks every delivery by hand: on time, late or very late. The monthly report said fifteen parcels were very late. The manager counted twelve. Nobody knows which three are different, and I suspect that it is the ones that are exactly on the edge.

Here is each delivery with the days that were promised and the days that it really took. A delivery that took the promised days or fewer is on time. One that was late by 1 or 2 days is late. One that was late by 3 days or more is very late. Please mark them all, count each mark, and tell me which delivery was worst.

The brief

What you need to know first.

  • Comparisons give True or False. a < b, a <= b, a > b, a >= b, a == b (two equals signs: one equals sign stores a value), a != b. The difference between > and >= is exactly one case, and that case is the edge.
  • if, elif, else. if late_by <= 0: runs its indented lines when the test is True; elif late_by >= 3: is tried only if the first test failed; else: catches the rest. Exactly one branch runs. Put the tests in an order where each one is a clear question.
  • Late by. late_by = actual_days - promised_days. Zero or less is on time (a day early is still on time). 1 or 2 is late. 3 or more is very late: exactly 3 is very late, not late.
  • Count, and find the worst. Count the labels with the counts.get(label, 0) + 1 pattern. For the worst, keep the biggest late_by seen so far starting from 0, and replace it only when a delivery is strictly more late; if nobody was late, the worst is None.
  • Fill in status(parcel), classify(req) returning {"labels", "counts", "worst_id"}, then the variables. The checks run classify on lists that you cannot see: exactly on time, late by 1, by 2, by exactly 3, and an empty list.

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 late-delivery note

Write the note for the support engineer: the rule in numbers (on time, late, very late, with the exact edges), how many deliveries fall in each group and which one was the worst, why a report and a manual count can differ by the deliveries that are exactly on an edge (three days is very late), and how to avoid it next time (state the rule in numbers, named limits, tests at the edges).

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: Late, Very Late, or On Time. What would you like to know?
📝

Knowledge Check

1 of 3

A delivery took 5 days and 5 were promised. Under the rule "on time means the promised days or fewer", it is:

⚑ Capture The Flag

Report a problem

About: /lessons/case-the-late-flags