#A small game
goblin = 20
dagger = 10
sword = 15
axe = 25
print('There is a goblin up ahead, what weapon would you like to choose? A dagger, a sword, or an axe?')
weapon = input()
print('You look around, and pick up the ' + weapon)
if weapon > goblin:
#A small game
goblin = 20
dagger = 10
sword = 15
axe = 25
print('There is a goblin up ahead, what weapon would you like to choose? A dagger, a sword, or an axe?')
weapon = input()
print('You look around, and pick up the ' + weapon)
if weapon > goblin:
print('You swing the ' + weapon + ' at the goblin, cutting its head off in succession!')
else:
print('You swing the ' + weapon + ' at the goblin, but fail to do enough damage. You are defeated.')
print('You swing the ' + weapon + ' at the goblin, cutting its head off in succession!')
else:
print('You swing the ' + weapon + ' at the goblin, but fail to do enough damage. You are defeated.')
—
I’m trying to make it so that if the player picks an axe, it registers as an int instead of a str. For example, if the player types ‘axe’, I want it so weapon = 25
Any advice?
>Solution :
You can hold the weapons in a dict and pick them with the input
weapons = {'dagger': 10, 'sword': 15, 'axe': 20}
weapon = input() # 'axe'
if weapons[weapon] > goblin:
print(...)