Lab · Python Programming
Lab: a kirana shop's stock and bill
The brief
Help Lakshmi Kirana Stores with a list of items to reorder, the bill for a phone order, the stock after the order and the shop's regular customers, using lists, tuples, dictionaries and sets.
Why it matters
Billing apps for small shops (and the big ones behind supermarket tills) are built on exactly these pieces: a price list, a stock count, an order of (item, quantity) pairs and a customer list. Reorder lists and "regular customer" offers come straight from them.
Skills you practise
- dictionaries and items()
- lists, append and sort
- tuple unpacking in a for loop
- sets: & and |
What you will have at the end
shop.py: a small stock-and-billing script that prints a reorder list, an order bill, the updated stock and the shop's regular customers.
How it is marked (rubric, 100 points)
| Correct resultsAll four checks pass, including soap being skipped and the out-of-stock oil being listed. | 50 |
|---|---|
| Right collection for the jobA dictionary for lookups, a list for the reorder list, tuple unpacking for order lines and sets for customers. | 25 |
| Safe with missing itemsUses in before looking up a key, so an unknown item never crashes the program. | 15 |
| Readable outputEach result is printed with a label a shopkeeper would understand. | 10 |
0/4 steps done
Step 1 of 4
What to reorder
low_stock is a sorted list of the items with fewer than 5 on the shelf (["oil", "tea"]).
stock.items() gives each item name with its count, so you can loop over both at once. Append an item to low_stock when its count is under 5. Out-of-stock items (0) are under 5 too. Then sort the list, so it is always in the same order.
Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.