PRACTICE

Errors & Exceptions

Lesson notes

Your task

Try converting "oops" to an int. Catch ValueError and print Invalid number.

Expected output
Invalid number
Loading…

OUTPUT

Worked solution
try:
    number = int("oops")
except ValueError:
    print("Invalid number")

Checks compare printed output, not your approach. Several solutions can be valid.

← Back to courses