promptdojo_

A traceback is a map — read bottom-up — step 8 of 8

Checkpoint

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

Last one. Cursor wrote a function get_price that pulls the "price" field out of an item dict and converts it to a float. Right now it crashes on three different inputs:

  • missing "price" key → KeyError
  • empty string for the price → ValueError
  • the dict is NoneTypeError from the None["price"] lookup

Rewrite the function so it returns 0.0 for any of those cases, and returns the parsed float when the value is valid. The script should print:

29.99
0.0
0.0
0.0

full-screen editor opens — close anytime to keep reading.