I am a beginner python coder trying to develop a simple text adventure game for a project. Most of the bugs and issues are relatively easy to resolve, but I keep having this one error when I try to reference an outside variable and add to it inside of a function.
Here's the code (using Python 3.9.5):
money = 0
def addmoney(q):
q = int(q)
money = money + q
print(f'Added {q} to Money: {money}')
print(f'You now have {money} money')
addmoney(100)
I keep getting an UnboundLocalError that says;
local variable 'money' referenced before assignment
I don't really understand what it means because I'm pretty sure I'm telling the function to add a specific quantity of money to the variable, but apparently I'm referencing it before giving it an assignment. It's probably something really easy that I'm missing, so hopefully someone can answer quickly before my mind blows in frustration lol.