I am currently making a game in Python, and now I want to add a store.
I want to do this with a variable. I know how to add variables, and how to change them, but not how to increase or decrease the variable.
I have actually never used variables before. I have read about it, but I don't remember much about it.
def level1():
os.system('cls')
gold = 500
print
print 'You have currently',
print (gold),
print 'gold'
time.sleep(3)
level2()
def level2():
print
print 'Congratulation! You completed the quest! You received 200 gold.'
time.sleep(2)
gold =+ 200
print 'You have now',
print (gold),
print 'gold.'
time.sleep(5)
And the result is:
You have currently 500 gold
Congratulation! You completed the quest! You received 200 gold. You have now 200 gold.
I tried gold + 200, gold += 200, and gold =+ 200, but only the last one worked.
I also tried
print 'You have now' + gold + 'gold'
But that didn't work for some reason. I also tried with
print 'You have now' + (gold) + 'gold'
I am not quite sure what's wrong here, and I would appreciate all the help I can get!
Thank you very much.
EDIT:
I forgot to add a huge part of my question. I am sorry for that!
==================================================================================
In the store, I will sell multiple items to different prices. Not all of the items will be available in the beginning of the game. Therefore I want an item to check how much gold the user have. If the user have under x gold, he can't buy that item.
If the level have reached level 04, that specific item will be unlocked.
gold += 200is the correct syntax. You might have an error elsewhere. Can you correct your indentation? Are these two functions entirely separate?gold =+ 200just setsgoldto+200, or200.