【发布时间】:2018-07-18 20:16:09
【问题描述】:
我正在编写一个简单的线性搜索程序。但它不会返回我搜索的任何索引,即使我已指定它在用户搜索列表中的项目时打印索引:
list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
tv = input("Search index:")
def LinearSearch():
for i in range(0,len(list)):
if list[i] == tv:
print("Found at index ", i)
LinearSearch()
【问题讨论】:
-
它不打印还是不返回结果?另外,这是 Python 2 还是 Python 3?因为,根据具体情况,
tv可能是int或str。 -
它不“打印”,它在 Python 3 中
标签: python python-3.x linear-search