
Checkpoint
Checkpoint: The Supply Desk
The Guild supply desk keeps every item in one table:
| item | island | qty | price |
|---|---|---|---|
| rope | Amber Isle | 3 | 4 |
| wick | Amber Isle | 0 | 1 |
qty is how many are in stock. price is in whole coins.
Customers ask questions all day. Let's answer them with SQL.
This checkpoint uses the whole chapter: INSERT, SELECT,
WHERE, ORDER BY, and ? placeholders. One new trick:
LIMIT ? takes a placeholder too.
Assignment
Use ? placeholders for every value that comes from an argument.
restock(conn, item, island, qty, price)inserts one row.in_stock(conn, island)returns a list of(item, qty)for that island withqtyabove 0, items A to Z.bargains(conn, max_price, how_many)returns a list of(item, price)withpriceat mostmax_price. Cheapest first, ties A to Z by item, and at mosthow_manyrows.
The program should print:
[('oil', 6), ('rope', 3)]
[('wick', 1), ('map', 2)]Use ? placeholders for every value that comes from an argument.
restock(conn, item, island, qty, price)inserts one row.in_stock(conn, island)returns a list of(item, qty)for that island withqtyabove 0, items A to Z.bargains(conn, max_price, how_many)returns a list of(item, price)withpriceat mostmax_price. Cheapest first, ties A to Z by item, and at mosthow_manyrows.
The program should print:
[('oil', 6), ('rope', 3)]
[('wick', 1), ('map', 2)]main.py Python sleeping
Press Run to try your code, then Check to test it.