error handling — when ai's code crashes mid-flight8 / 9
try/except — catching what ai didn't
Write a function called safe_int that takes one argument text and
returns int(text) if it parses, or the integer 0 if it raises a
ValueError. Then call it twice and print the results:
print(safe_int("42"))
print(safe_int("hello"))
Expected output:
42
0
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _