-4
def foo(x):
    assert x!=0
    return 1/x

try:
    print(foo(0))
except ZeroDivisionError:
    print("zero")
except:
    print("some")

I think the output must be AssertionError.

Can anyone explain this code? I think the expected output of this code may throw an assertion error, but the actual answer is 'some' from the last except block. Or otherwise, if the return statement is executed, then the answer should be zero from the ZeroDivisionError.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

0 Answers0