tracebacks — cursor wrote this and crashed9 / 9
diagnose any crash in one read
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
None→AttributeErrorfrom the.getcall
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
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _