Editor

Low Stock Alert System

Advanced · Write the code · from Build an Inventory Management System with SQLite

From the lesson: Step 5: Low Stock Alerts

Running out of stock means lost sales. Each product has a reorder_level - when quantity drops to or below this level, the system should raise an alert. This is one of the most valuable features of any inventory system.

Read this part of the lesson

Write a function check_low_stock(cursor) that:

1. Queries all products where quantity <= reorder_level.

2. Prints "=== LOW STOCK ALERTS ===" as a header.

3. For each low-stock product, prints "ALERT: {name} has {quantity} units (reorder at {reorder_level})".

4. If no products are low, prints "All stock levels OK".

5. Returns the list of low-stock product names.

Set up a database with products at various stock levels (some below their reorder level) and test the function.

import sqlite3
def check_low_stock(cursor):
# Find and report products below reorder level
pass
# Set up database with mixed stock levels and test alerts

More Inventory System exercises

All Python exercises · 50 practice problems · Practical Projects quiz