Posted by: Pdfprep
Post Date: January 26, 2021
What is the expected behavior of the following code?
A . it outputs 2
B . the code is erroneous and it will not execute
C . it outputs 1
D . it outputs 3
Answer: D
Comments (2)
Correct answer is C, not D, since the assert condition returns False end then an AssertionError exception is raised just after foo(0) is executed.
Choice “D” is wrong. The correct choice is “C”.
Explanation : Since m = 0, try foo(0) fails and raises “AssertionError” not “ArithmeticError” which is the last block. Hence, m’s value becomes “m = m +1” that is 0 + 1 = 1.