我已经把这个代码放进了一个更大的代码块中,但是我把它缩小到了这个错误。我知道错误是我试图在字典中添加变量。有没有办法我可以把它加到实际的数据里?你知道吗
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
把你的数据收集起来,然后像这样使用。你知道吗
要打印值,可以执行以下操作
我从您的代码中猜测
statlist
是一个包含stat
键和stat value
值的字典。现在你有了一个列表,所以本质上你说的是“如果这个项目在列表中,请在它的末尾加上一个数字”(尽管不正确)。你知道吗你要做的是给问题加上词典。第一部分,声明变量,并不完全必要,您可以这样完成:
对于每个值。然后,要更改统计信息:
您的示例当前没有词典。你搞错了。具体如下:
一旦你有了正确的字典初始化
在分发点时,您也有一些逻辑问题,但您可以自己解决。你知道吗
相关问题 更多 >
编程相关推荐