Stock Level Report
Advanced · Write the code · from Build an Inventory Management System with SQLite
From the lesson: Step 4: Check Stock Levels
A warehouse manager needs to see stock levels at a glance. Let's build a function that queries the products table and returns a formatted stock report. We can also calculate the total inventory value (quantity times price for each product).
Read this part of the lessonWrite a function get_stock_report(cursor) that:
1. Queries all products and returns a list of dictionaries with keys: name, category, quantity, price, value (quantity * price).
2. Prints a formatted stock report with headers.
3. Prints the total inventory value at the end.
Format: "=== STOCK REPORT ===" header, then each product as "{name}: {quantity} units @ ${price:.2f} = ${value:.2f}", then "Total inventory value: ${total:.2f}".
Set up a database with at least 3 products (with quantities > 0) and call the function.
More Inventory System exercises
- Create the Database SchemaAdvanced
- Write the Add Product FunctionAdvanced
- Record TransactionsAdvanced
- Low Stock Alert SystemAdvanced
- Transaction History ReportAdvanced
- The Complete InventorySystem ClassAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz