Editor

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 lesson

Write 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.

import sqlite3
def get_stock_report(cursor):
# Query products and print formatted stock report
pass
# Set up database, add products with stock, generate report

More Inventory System exercises

All Python exercises · 50 practice problems · Practical Projects quiz