+ 1
Please why is this code not working?
def definex(a): x=a definex(2) print(x)
3 Answers
+ 6
The variable "x" is only accessible in the function definex() and cannot be used outside it, i.e. It has a local scope.
To use it outside the function, you will have to give it a global scope.
Corrected Code -
def definex(a):
global x
x = a
definex(2)
print(x)
Notice the second line, it declares a Global scope to the variable"x" . so we can use it anywhere
+ 2
print within function or
return x and print(definex(2))
+ 1
okk