promptdojo_

Diagnose any crash in one read — step 9 of 9

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 NoneAttributeError from the .get call

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.