Skip to content

04-13: Inventory Manager

Python: Fundamentals

View the live site — ijk37.com

Project 13

Home  |  All Projects  |  Notes  |  Exercises  |  Quiz Hub

Manages a shop's stock with add, restock, sell, delete, and low-stock reporting. Sorting by name/qty/price/category. Total stock value calculated automatically. Low-stock items flagged with ⚠️.

Topics covered: nested dicts · list comprehensions · raise ValueError/KeyError · try/except · sorted(key=lambda) · del dict[key] · accumulation · functions

Difficulty: ⭐⭐ Beginner–Intermediate


How to Run

python main.py

Sample Output

  Product                Qty      Price  Category
  ───────────────────────────────────────────────────────
  Bread                   45    ৳  60.00  Bakery
  Chicken                 80    ৳ 280.00  Protein
  Eggs                     6    ৳ 155.00  Protein ⚠️
  Milk                    30    ৳  90.00  Dairy
  Salt                     8    ৳  20.00  Groceries ⚠️
  ...
  8 product(s)   Total stock value: ৳97,810.00

Key Concepts Practised

Concept Where used
raise ValueError Input validation in add_product(), sell()
raise KeyError Product-not-found in restock(), sell()
List comprehension + condition get_low_stock()
Lambda sort key sorted(inventory.items(), key=key_func)
Dict of dicts inventory = {name: {qty, price, category}}