Issue
I'm starting with some basic stuff to get a feeling for how to make a text based game. After creating the .py file in my IDE, I open terminal and use bash to open the .py file.
hpGanon = 10
damage = input("How much damage did you do with the Master Sword?")
hpGanon = hpGanon - damage
print("Ganon now has " + hpGanon + "hit points.")
At the end when I want it to print, bash tells me it cannot concatenate 'str' and 'int' objects. I tried following what was said in the following post, Python: TypeError: cannot concatenate 'str' and 'int' objects But I'm not getting the result I want.
I just want it to say: "Ganon now has x hit points." Any ideas?
Solution
I'm not entirely sure (I have never coded with Python before) but it seems that the hpGanon variable is an integer and not a string, so it cannot put the two together. To convert an integer to a string in Python (I searched this up :P), you need to do str(integer)
.
So, to implement this in your example, try something like this:
print("Ganon now has " + str(hpGanon) + "hit points.")
Answered By - aimorris
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.