Level 2 / Project 08 - Mini Inventory Engine¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Estimated time: 40 minutes
Focus¶
- stock add/remove and reorder alerts
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-2/08-mini-inventory-engine
python project.py --inventory data/sample_input.txt
python project.py --inventory data/sample_input.txt --low-stock
python project.py --inventory data/sample_input.txt --value
python project.py --inventory data/sample_input.txt --search "key"
pytest -q
Expected terminal output¶
Expected artifacts¶
- Inventory listing on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
--removecommand:--remove "Widget" 5to decrease stock. - Add an
--exportflag that writes current inventory to a new CSV. - Add a
--categoryfilter to show only items in a specific category.
Break it (required) — Core¶
- Add an item with negative quantity — is it allowed?
- Remove exactly all stock of an item — does it stay at 0 or get deleted?
- Load a CSV with non-numeric price values — what happens?
Fix it (required) — Core¶
- Add validation that quantity and price must be non-negative.
- Decide and document what happens when stock reaches 0.
- Handle CSV parsing errors with try/except and skip bad rows.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why is the inventory stored as a dict-of-dicts instead of a list?
- How does
dict.get(key, default)help avoid KeyError? - What is the difference between mutating a dict vs returning a new one?
- Where would this pattern be used in a real e-commerce system?
Mastery check¶
You can move on when you can: - implement add/remove/search from memory, - explain how nested dicts model real-world entities, - add a new feature (e.g. price history) without breaking existing code, - describe why the function returns a result dict instead of raising exceptions.
Related Concepts¶
| ← Prev | Home | Next → |
|---|---|---|