promptdojo_
Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Last drill. Write a tiny order system:

  1. Define a custom exception class OutOfStock that inherits from Exception.
  2. Define a function place_order(inventory, item, qty) that:
    • Raises KeyError(item) if item is not in inventory.
    • Raises OutOfStock(f"only {inventory[item]} left of {item}") if inventory[item] < qty.
    • Otherwise returns the string f"shipped {qty} {item}".
  3. Loop over three orders. For each, wrap the call in try/except (KeyError, OutOfStock) as err: print(err).

Use this inventory and these orders:

inventory = {"book": 5, "pen": 0}
orders = [("book", 2), ("pen", 1), ("hat", 1)]

Expected output:

shipped 2 book
only 0 left of pen
'hat'

this step needs the editor

on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.

open this same url on a laptop to keep going today.