QuestionQ75

Exceptions

What is the expected behavior of this code?

Question Image

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

The assertion fails because the global variable m is initially 0. This raises AssertionError, which is not an ArithmeticError; the outer catch-all except handles it, increments m to 1, and the program prints 1.

Community Discussion

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