I'm trying to write a text game, and I came across an error in the function that I define, which allows you to basically spend your skill points after you create your character. At first, the error showed that I was trying to subtract a string from an integer in this part of the code: balance - strength . Obviously, this was wrong, so I fixed it with strength = int(strength) ... but now I get this error that I have never seen before (new programmer), and I'm stumped that it is he trying to tell me how I correct it.
Here is my code for the part of the function that doesn't work:
def attributeSelection(): balance = 25 print("Your SP balance is currently 25.") strength = input("How much SP do you want to put into strength?") strength = int(strength) balanceAfterStrength = balance - strength if balanceAfterStrength == 0: print("Your SP balance is now 0.") attributeConfirmation() elif strength < 0: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif strength > balance: print("That is an invalid input. Restarting attribute selection. Keep an eye on your balance this time!") attributeSelection() elif balanceAfterStrength > 0 and balanceAfterStrength < 26: print("Ok. You're balance is now at " + balanceAfterStrength + " skill points.") else: print("That is an invalid input. Restarting attribute selection.") attributeSelection()
And here is the error that I get when I get to this part of the code in the shell:
Your SP balance is currently 25. How much SP do you want to put into strength?5 Traceback (most recent call last): File "C:\Python32\APOCALYPSE GAME LIBRARY\apocalypseGame.py", line 205, in <module> gender() File "C:\Python32\APOCALYPSE GAME LIBRARY\apocalypseGame.py", line 22, in gender customizationMan() File "C:\Python32\APOCALYPSE GAME LIBRARY\apocalypseGame.py", line 54, in customizationMan characterConfirmation() File "C:\Python32\APOCALYPSE GAME LIBRARY\apocalypseGame.py", line 93, in characterConfirmation characterConfirmation() File "C:\Python32\APOCALYPSE GAME LIBRARY\apocalypseGame.py", line 85, in characterConfirmation attributeSelection() File "C:\Python32\APOCALYPSE GAME LIBRARY\apocalypseGame.py", line 143, in attributeSelection print("Ok. You're balance is now at " + balanceAfterStrength + " skill points.") TypeError: Can't convert 'int' object to str implicitly
Does anyone know how to solve this? Thanks in advance.
python string int implicit
Tyler Haddaway Nov 30 '12 at 22:34 2012-11-30 22:34
source share