Handle a failed conversion
Take your time, follow the code and check your understanding.
Move blocks into orderExceptions
print(value)
value = 0
except ValueError:
value = int("not-a-number")try:
Your answer3 min · no timer
Drag blocks, or use the arrow buttons. Keep the displayed indentation. This task uses the taught sequence; other equivalent programs may also be valid.
Show solution and explanation
The except clause handles conversion failure and assigns the fallback before print.
try:
value = int("not-a-number")
except ValueError:
value = 0
print(value)