QuestionQ14

VerifiedExceptions

What is the anticipated behavior of the following code?

Question Image

Explanation

Converting the string '2A' to an integer raises a ValueError. That exception is not handled by the preceding TypeError or LookupError clauses, so the catch-all except clause runs, sets n to 1, and the program prints 1.

Community Discussion

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