Code Room
Code reviewHard
Question
Review this Python function that records a sale: it writes the ledger entry, then updates inventory.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
def record_sale(conn, sku, qty, amount): cur = conn.cursor() cur.execute("INSERT INTO ledger (sku, amount) VALUES (%s, %s)", (sku, amount)) try: cur.execute("UPDATE inventory SET qty = qty - %s WHERE sku = %s", (qty, sku)) except Exception as e: logging.warning("inventory update failed: %s", e) conn.commit() return "ok"Run or narrate your approach, then ask the coach.