【发布时间】:2018-11-19 12:14:28
【问题描述】:
我希望用户可以输入数字,如果数字与列表值匹配,则程序返回输入的值,它也是索引。
我该怎么做? 我已经写了几行代码,但它不起作用....
a = [10, 20, 30, 40, 50, 60]
inp = int(input("Enter digit"))
i =0
for i in a:
if inp == a[i]:
print("You found it {}".format(a[i]))
else:
print("No found")
它引发了一个 IndexError。
【问题讨论】:
标签: python python-3.x error-handling