+ 1
Problem with Variables
I want to change the global a Why Error? a = 4 def func(): print(a) a += 2 func() https://code.sololearn.com/cOQ3t7h3DllB/?ref=app
4 ответов
+ 1
this is yours:
a = 4
def func():
print(a)
a += 2
func()
And this is one of the many right ones:
a = 4
def func(x):
print(x+2)
func(a)
And if you want to affect the variable outside of the function scope, then:
a = 4
def func():
global a
print(a)
a += 2
func()
+ 3
Insert in func dimension "global a"
https://code.sololearn.com/cjhL2EYSl5j8/?ref=app
+ 2
a=4
def func(a):
print(a)
a += 2
func(a)
I think 🤔 it's showing an error because you didn't called the argument.
0
you print the value of a variable that does not exist in the function