why an error occur in the below program code
Title
Question
a=10
b=20
print(id(a))
def func(x,y):
y=a
a=2
print(y)
return x+y
n1=int(input("Enter no"))
n2=int(input("Enter"))
print(func(n1,n2))
Python-3.4.3 Getting-Started-with-Functions 02-03 min 40-50 sec
Answers:
It seems that the function part is not indented properly.
This is because you are using a global variable inside a function. You are using 'a' in func(x, y) but 'a' is global.
To use a global variable inside a function add 'global a' inside a function.
Login to add comment