Inventory logic flags records whose stock has reached a reorder threshold.

threshold checks A threshold check turns a numeric comparison into a small decision list.

Inventory Alerts

reorder_level
inventory_alerts.py
Replay: real traced execution (multi-file project)
items = [
    {"sku": "pen", "stock": 8},
    {"sku": "notebook", "stock": 3},
    {"sku": "marker", "stock": 12},
]

reorder_level = 5

alerts = []
for item in items:
    if item["stock"] <= reorder_level:
        alerts.append(item["sku"])

print("alerts=" + ",".join(alerts))
items = [
    {"sku": "pen", "stock": 8},
    {"sku": "notebook", "stock": 3},
    {"sku": "marker", "stock": 12},
]

reorder_level = 10

alerts = []
for item in items:
    if item["stock"] <= reorder_level:
        alerts.append(item["sku"])

print("alerts=" + ",".join(alerts))
  1. items ← [{'sku': 'pen', 'stock': 8}, {'sku': 'notebook', 'stock': 3}, {'sku': 'marker', 'stock': 12}]

    1items→ [{'sku': 'pen', 'stock': 8}, {'sku': 'notebook', 'stock': 3}, {'sku': 'marker', 'stock': 12}] = [2    {"sku": "pen", "stock": 8},3    {"sku": "notebook", "stock": 3},4    {"sku": "marker", "stock": 12},5]67reorder_level→ 5 = 5  #@reorder_level=1089alerts→ [] = []10for item in items:
  2. for item in items:

    pass 1 of 3
    9alerts = []10for item{'sku': 'pen', 'stock': 8} in items[{'sku': 'pen', 'stock': 8}, {'sku': 'notebook', 'stock': 3}, {'sku': 'marker', 'stock': 12}]:11    if item["stock"] <= reorder_level:12        alerts.append(item["sku"])
    All 3 passes — pass 1 is the card above
    passitemitem[”stock”]reorder_levelitem[”sku”]alerts
    1{'sku': 'pen', 'stock': 8}
    2{'sku': 'notebook', 'stock': 3}35notebook[] ['notebook']
    3{'sku': 'marker', 'stock': 12}
  3. alerts ← ['notebook']

    10for item in items:11    if item["stock"]3 <= reorder_level5:12        alerts→ ['notebook'].append(item["sku"]notebook)
  4. print("alerts=" + ",".join(alerts))

    14print("alerts=" + ",".join(alerts['notebook']))
    outputalerts=notebook
  1. items ← [{'sku': 'pen', 'stock': 8}, {'sku': 'notebook', 'stock': 3}, {'sku': 'marker', 'stock': 12}]

    1items→ [{'sku': 'pen', 'stock': 8}, {'sku': 'notebook', 'stock': 3}, {'sku': 'marker', 'stock': 12}] = [2    {"sku": "pen", "stock": 8},3    {"sku": "notebook", "stock": 3},4    {"sku": "marker", "stock": 12},5]67reorder_level→ 10 = 1089alerts→ [] = []10for item in items:
  2. for item in items:

    pass 1 of 3
    9alerts = []10for item{'sku': 'pen', 'stock': 8} in items[{'sku': 'pen', 'stock': 8}, {'sku': 'notebook', 'stock': 3}, {'sku': 'marker', 'stock': 12}]:11    if item["stock"] <= reorder_level:12        alerts.append(item["sku"])
    All 3 passes — pass 1 is the card above
    passitemitem[”stock”]reorder_levelitem[”sku”]alerts
    1{'sku': 'pen', 'stock': 8}810pen[] ['pen']
    2{'sku': 'notebook', 'stock': 3}310notebook['pen'] ['pen', 'notebook']
    3{'sku': 'marker', 'stock': 12}
  3. alerts ← ['pen']

    pass 1 of 2
    10for item in items:11    if item["stock"]8 <= reorder_level10:12        alerts→ ['pen'].append(item["sku"]pen)
  4. alerts ← ['pen', 'notebook']

    pass 2 of 2
    10for item in items:11    if item["stock"]3 <= reorder_level10:12        alerts→ ['pen', 'notebook'].append(item["sku"]notebook)
  5. print("alerts=" + ",".join(alerts))

    14print("alerts=" + ",".join(alerts['pen', 'notebook']))
    outputalerts=pen,notebook