Reputation: 9
I keep getting this error
TypeError: unsupported operand type(s) for +: 'int' and 'str'
In my below code:
done = False
while not done:
if You.Hit_points > 0 and Opponent.Hit_points > 0:
move = raw_input("Would you like to make a move? (y/n) ")
if move == "y":
print "",You.name,"hit ",Opponent.name," by",You.Hit_points," hit points!"
Opponent.Health = You.Hit_points + You.Skill_points + Opponent.Health
Thank you!
Upvotes: 0
Views: 86
Reputation: 18633
At least one of Opponent.Health
, You.Hit_points
, and You.Skill_points
is a string, and at least of them is a number(an int). You're trying to add together strings and numbers. If you intend for all of those values to be numbers, you need to figure out which one isn't and change that. You could cast all of the values to int
but that's a short-term solution, this is a problem that will keep coming up if you don't fix it.
All the information you need is in the error: unsupported operand type(s) for +: 'int' and 'str'
Upvotes: 4
Reputation: 3284
Hit_points is probably an int. Convert it to a string:
str(You.Hit_points)
Edit:
Wait, no. Misread, Nolen Royalty is correct. This would probably suffice:
Opponent.Health=int(You.Hit_points)+int(You.Skill_points)+int(Opponent.Health)
But I would follow Nolen's recommendations.
Upvotes: 1