日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python中object转str_Python-TypeError:无法将“ int”对象隐式转换为str

發布時間:2024/9/30 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中object转str_Python-TypeError:无法将“ int”对象隐式转换为str 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在嘗試編寫文本游戲,但在定義的函數中遇到了錯誤,該錯誤使你基本上無法在制作角色后花費技能點。最初,錯誤表明我正在嘗試從代碼的這一部分的整數中減去一個字符串balance - strength。顯然這是錯誤的,所以我用strength = int(strength)… 修復了它,但是現在我遇到了一個以前從未見過的錯誤(新程序員),并且我對確切要告訴我的內容以及如何解決它感到困惑。

這是我的部分功能不起作用的代碼:

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()

這是我在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

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

有誰知道如何解決這個問題?謝謝你

總結

以上是生活随笔為你收集整理的python中object转str_Python-TypeError:无法将“ int”对象隐式转换为str的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。