I have a variable a, and I want a to be added with b, like so:
a = a + b
Now, I have my program set up like so:
a = 2
b = 3
def add() :
a = a + b
print(str(a))
add()
Every time I run this, I get
Traceback (most recent call last):
File "<stdin>", line 8, in <module>
File "<stdin>", line 5, in add
UnboundLocalError: local variable 'a' referenced before assignment
instead of
5
Please explain the obvious mistake that I am making.