QuestionQ79

Exceptions

What is the expected behavior for the following code?

Question Image

  • A the code is erroneous and it will not execute
  • B it outputs 1
  • C it outputs 2
  • D it outputs 0
Explanation

Converting '2A' with int() raises ValueError because it is not a valid integer literal. The matching except ValueError block assigns 2 to n, so print(n) outputs 2.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!