promptdojo_

Raising errors — making your code fail loudly on purpose — step 8 of 9

Write a function validate_age(age) that:

  • Returns age unchanged when age is an integer between 0 and 120 (inclusive).
  • Raises ValueError with the message f"age out of range: {age}" otherwise.

Then call it three times inside try/except ValueError as err: print(err) blocks so the output below prints. Use print(validate_age(...)) for the happy-path call.

Expected output:

30
age out of range: -5
age out of range: 200

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