I'm Trying to subtract a Variable from a Variable and its not working
KeeganMcGough (0)

I am making a random based fighter game.
I want to make it so when you do one punch its between 1-20 and then subtract that number from the opposing players health but it is not working.
If you could check it out it would be very helpful :D

print ("What Move?")
answer = raw_input(">")
if (answer == "punch"):
print ("Player 2 hits Player 1")
print ((Player1) - (punch))
print (Player1)
else:
print ("That is not a move")

https://repl.it/@KeeganMcGough/Fighter

You are viewing a single comment. View All
IbraheemRodrigues (86)

@KeeganMcGough You perform the subtraction correctly, but the only thing that you do with that value is print it. You have not told python to store it as the new value of player1

player1 = player1 - punch will do this.
There is also player1 -= punch1, which is a short hand for the above
So your code should look like:

if (answer == "punch"):
    print ("Player 2 hits Player 1")
    Player1 = Player1 - punch # Perform the subtraction and store it back into the `Player1` var
    print (Player1) # Print this new value
else:
    print ("That is not a move")