Mini project — library late-fee + lab board

Two small systems share one skill: a function with a rule, then a report. The library charges ₹5 per extra day after a 7-day loan. A lab dashboard flags utilisation over 80%. This is how school software actually starts — not with pygame, with a fee and a percentage.

Library desk

A fee function you can test.

You will be able to

  • Combine functions, decisions and a table of records
  • Handle the zero-fee / OK cases

Late fee

If days is 10, extra is 3, fee is 15. If days is 7 or less, extra is 0. Returning 0 lets callers add fees without special cases: total += late_fee(d).

Utilisation

percent = used * 100 / seats. Guard seats > 0 in real apps. Flag Over if percent >= 80 else OK. The same pattern is a pandas column: df["pct"] = df.used * 100 / df.seats.

Words that matter

Business rule
A number the institution chose (7 days, 80%) — keep it in one function.

Common mistakes

Avoid: Copying 5 and 7 into five files.

Do this: One function owns the rule.

Example program — Late fee function

Try days = 7 and days = 12.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Your turn — Fee for 9 days

Print the fee for 9 days kept (2 extra days × 5 = 10) so 10 appears.

Python sandboxlesson://workspace
console

Edit the example, press Run, then Build if you want a compile check.

build

Press Build to compile.

Self-assessment

Check your understanding before you mark the lesson complete.

1. Returning 0 for an on-time book is useful because…

Progress is stored in a browser cookie on this device.