列表索引必须是整数,而不是来自用户输入的str

时间:2016-08-17 23:27:18

标签: python python-3.x

Tools_List=["Hoe","Pitchfork","Shovel"] #`list`
print(Tools_List)
Tools=input("What tools do you want? ")  
print(Tools_List[Tools])

1 个答案:

答案 0 :(得分:0)

只能将一个索引作为时间索引,当您的提示要求“工具”复数时。我建议(使用int校正和小写名称)

tools = ["Hoe","Pitchfork","Shovel"]
print(tools)
tool = int(input("What tool do you want? "))
print(tools[tool])