我已經將這段代碼放入了一大段代碼中,但是我將其縮小爲這個錯誤。我知道這個錯誤是我正試圖在字典中添加一個變量。有什麼方法可以將其添加到實際統計數據本身?如何將數字添加到字典中的變量?
smallGuns = 5
bigGuns = 2
unarmed = 3
meleeWeapons = 20
throwing = 4
firstAid = 2
sneak = 5
lockpick = 10
steal = 3
science = 4
repair = 3
speech = 5
choice = raw_input("Which stat do you want to add points to?")
skillPoints = 5
statlist = ['small guns', 'big guns', 'unarmed', 'melee weapons', 'throwing', 'first aid' 'sneak', 'lockpick', 'steal', 'science', 'repair', 'speech']
if choice in statlist:
pointDeduction = input("How many points do you wish to add to %s? (Up to %s points)" %(choice, skillPoints))
if pointDeduction <= choice:
choice += pointDeduction
skillPoints -= pointDeduction
else:
print "You do not have that many points to distribute to %s." %(choice)
print steal
我的錯誤信息是
Traceback (most recent call last): File "F:/TARG/temp.py", line 22, in <module> choice += pointDeduction TypeError: cannot concatenate 'str' and 'int' objects
你能後的實際的錯誤信息? – michaelpri
錯誤消息: 回溯(最近最後調用): 文件 「F:/TARG/temp.py」,第22行,在 選擇+ = pointDeduction 類型錯誤:不能連接 'STR' 和 'INT' 對象 –
TyTheChosenOne
搜索該錯誤消息「TypeError:無法連接'str'和'int'對象」,會直接導致各種(StackOverflow)相關答案和解決方案。 – Evert