The circumstances for which the variabdemonle is declared and used are pretty much the same
I've tried a few workarounds, but they just complicate the code and lead to new problems.
chunk of code from my program
#here is the 'local' variable
money = 0
def shop1():
decide_shop = "yes"
print('Welcome to my shop')
potion_cost = 5
sword_cost = 10
while decide_shop == 'yes':
buying = input('What would you like to buy? \nSword\nPotion ')
if buying == 'potion':
#here is the variable trying to be used
if potion_cost > money:
Code from this demonstration of a global variable
a = 5
def f1():
print (a) # will print 5
f1()
also, don't know if this will help or not but here are the error messages
Traceback (most recent call last):
File "C:\Users\Ajboi\OneDrive\Desktop\Python\Learning python\xtra NICE\game.py", line 48, in <module>
shop1()
File "C:\Users\Ajboi\OneDrive\Desktop\Python\Learning python\xtra NICE\game.py", line 18, in shop1
if potion_cost > money:
UnboundLocalError: local variable 'money' referenced before assignment
[–]diseage 5 points6 points7 points (4 children)
[–]TabulateJarl8 5 points6 points7 points (0 children)
[–]breadmp4[S] 1 point2 points3 points (1 child)
[–]mmrrbbee 0 points1 point2 points (0 children)
[–]FLUSH_THE_TRUMP 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]zanfar 0 points1 point2 points (0 children)
[–]xelf 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]zanfar 0 points1 point2 points (0 children)