Here's my code:
def displayInventory ():
print ("Inventory: " + str(inventory))
def enterEcdysis():
global xcash
xcash -= 1
displayInventory()
xcash = 3
inventory = [str(xcash) + ' Cash',]
enterEcdysis()
I'm trying to make this print ['2 Cash,'], but when I run it it still comes out as 3. I'm not sure exactly what I'm doing wrong here. Shouldn't xcash -= 1 take one away from the global variable?
It is updating xcash. The problem is inventory is out of date. You're setting it to ['3 Cash'] before the call to enterEcdysis() and you don't update it after xcash is modified.
Change your print statement to print xcash directly and you'll see it's working fine:
def displayInventory ():
print ("Inventory: {} Cash".format(xcash))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With