try/except — catching what AI didn't — step 8 of 9
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.read, then continue.
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
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.