QuestionQ64

VerifiedFunctions and Exceptions

What is the expected outcome when the following code is run?

Question Image

Explanation

In Python, an augmented assignment to a name inside a function makes that name local to the function unless it is declared global or nonlocal. variable += parameter[0] attempts to read that uninitialized local variable first, causing an UnboundLocalError that is not handled.

Community Discussion

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