def fi(n):
print(counter)
data = counter + 1
return data
counter = 2
print(fi(10))
How can this code work well??
I guess this code doesn't work well because of counter
in fi()
function, there's no declaration of counter
...
def fi(n):
print(counter)
data = counter + 1
return data
counter = 2
print(fi(10))
How can this code work well??
I guess this code doesn't work well because of counter
in fi()
function, there's no declaration of counter
...
You are mis-using the counter variable; to keep your function pure, just use n in the function, e.g.:
def fi(n):
print(n)
data = n + 1
return data
counter = 2
print(fi(counter))