QuestionQ15

VerifiedExceptions

Which of the following code snippets execute without producing any unhandled exceptions?

Choose two
Explanation

A bare except clause catches the ZeroDivisionError from 0 / 0 and the ValueError from math.sqrt(-1). The corresponding exception handlers in both snippets perform valid calculations, so execution completes normally. In contrast, successful try blocks cause their else blocks to run; converting an empty string with int() or the invalid string "1c1" with float() raises an unhandled ValueError.

Community Discussion

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