Single Choice Not Set

QWhat will be the output after the following statements?
def abc():
    print(x)
    x = 10
abc()
x = 20

ID: #3971 Python Errors and Exceptions Handling 312 views
Question Info
#3971Q ID
Not SetDifficulty
Python Errors and Exceptions HandlingTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A NameError
  • B 20
  • C 10
  • D UnboundLocalError
Correct Answer

Explanation

UnboundLocalError
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Input In [61], in ()
      2     print(x)
      3     x = 10
----> 4 abc()
      5 x = 20

Input In [61], in abc()
      1 def abc():
----> 2     print(x)
      3     x = 10

UnboundLocalError: local variable 'x' referenced before assignment

Share This Question

Challenge a friend or share with your study group.