This question already has an answer here:
This is my code for a shop in my Python RPG game. Whatever value I select, the code executes the things for if I typed dagger. It also never tells me that I have insufficient funds. Always the same answer
global gcredits
dagger = Item('Iron dagger', 5, 5)
sword = Item('Iron sword', 10, 12)
armour = Item('Iron Armour', 15, 20)
print ("Welcome to the shop! Buy all your amour and weapon needs here!")
print ("You have",gcredits,"Galactic Credits!")
print (dagger.name,': Cost:', dagger.value,'Attack points:', dagger.hvalue)
print (sword.name,': Cost:', sword.value,'Attack points:', sword.hvalue)
print (armour.name,': Cost:', armour.value,'Attack points:', armour.hvalue)
choice = input('What would you like to buy?').upper()
if choice == 'DAGGER' or 'IRON DAGGER' or 'IRONDAGGER':
print ("You have selected the Iron Dagger.")
if gcredits >= 5:
print ('Purchase successful')
gcredits = gcredits - 5
dEquip = True
shop()
elif gcredits < 5:
print ("You have got insufficient funds")
shop()
elif choice == 'SWORD' or 'IRON SWORD' or 'IRONSWORD':
if gcredits >= 10:
print ('Purchase successful')
gcredits = gcredits - 10
sEquip = True
shop()
elif gcredits < 10:
print ("You have got insufficient funds")
shop()
elif choice == 'ARMOUR' or 'IRON ARMOUR' or 'IRONARMOUR':
if gcredits >= 15:
print ('Purchase successful')
gcredits = gcredits - 15
aEquip = True
shop()
elif gcredits < 15:
print ("You have got insufficient funds")
shop()
else:
print ("That is not an item. Try again.")
shop()
Aucun commentaire:
Enregistrer un commentaire