You just learned about try and except for handling exceptions. Time to catch a real one.
A script tries to convert user input to an integer with int(). Sometimes the input is not a valid number and Python raises a ValueError. Your job is to wrap the risky code in a try block so the program handles the error gracefully instead of crashing.
Your tasks
Given this starting value:
1. Wrap int(user_input) in a try block and store the result in a variable called age
2. Add an except ValueError block that sets age = 0 when the conversion fails
3. Print age
Expected output
0
Constraints
- Use
try and except ValueError — do not use a bare except:
- Do not check the input with
if or isdigit() — the whole point is to let the exception happen and catch it
- No external libraries