attributes = [["strength", 0], ["health", 0], ["wisdom", 0], ["dexterity", 0]]
attrib = raw_input("Which attribute would you like to add these points to? ")
int(attrib)
print attributes[attrib][1]
输出:
List indices must be integers, not str
我希望属性是用户输入的数字。我不知道为什么我会收到此错误,因为在我看来,我已经将字符串转换为第 3 行的整数。
我猜我不允许以这种方式访问嵌套列表?失去。。。
int(attrib)
不会将attrib
的内容"修改"为整数;它返回整数。你想要的是这个,相反:
attrib = int(attrib)