promptdojo_

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

full-screen editor opens — close anytime to keep reading.