promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_

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

Checkpoint

One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.

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.