I'm something of a newbie to Python coding and I've just been making short games to get into writing code more fluently. I have right now a "simulation" that is essentially a text-based fight between a hero and a goblin. I am using a tuple to store the moves list and then calling on the elements in that tuple in a series of if statements. MY problem is that when the user enters the number 2, the "potion" move is used, but when the user enter 3, the "potion" move is also used. The number 2 should trigger the "block" move, but does not. I think this may have to do with my limited knowledge of tuples, but can anyone clarify this for me? Much appreciated. The code is as follows...
#begins battle loop
while goblin > 0:
hmoves = ('sword',
'shield bash',
'block',
'potion')
choice = int(input("\nEnter a number 0 - 3 to choose an attack: "))
if hmoves[choice] is 'sword':
print(name, "attacked with his sword!")
goblin -= 3
print("\ngoblin used bite!")
hero -= 2
print("Goblin HP:", goblin, "Hero HP:", hero)
elif hmoves[choice] is 'shield bash':
print(name, "used shield bash!")
goblin -= 2
print("\ngoblin used bite!")
hero -= 2
print("\nGoblin HP:", goblin, "Hero HP:", hero)
elif hmoves[choice] is 'block':
print(name, "used block!")
print("\ngoblin used bite!")
print("but it was blocked.")
hero = hero
goblin = goblin
print("\nGoblin HP:", goblin, "Hero HP:", hero)
elif hmoves[choice] is 'potion':
print(name, "used a health potion.")
hero += 4
print("\ngoblin used bite!")
hero -= 2
print("\nGoblin HP:", goblin, "Hero HP:", hero)
#print("Goblin HP:", goblin, "Hero HP:", hero)
if goblin <= 0:
print("Congratulations you've completed the simulation.")
else:
print("Sorry, you did not pass the simulation.")