Morning,
Firsly, as a
is outside of a function, you need to define within the function that you are using a global variable:
This would look like this:
def mains():
global a #Lets the function know the variable is already defined outside the scope
if True:
a=add(10,20)
Secondly, I'm not sure how your function is set up but you actually need to call the function mains()
for it to run that function.
This code works for me:
a=0
def add(x,y):
return x+y
def mains():
global a #Lets the function know the variable is already defined outside the scope
if True:
a=add(10,20)
mains()
print(a)