为了分析搜索算法,我们需要定一个基本计算单位。回想一下,这通常是为了解决问题要重复的
共同步骤。对于搜索,计算比较操作数是有意义的。每个比较都有可能找到我们正在寻找的项
代码如下:
def sequen(alist,item):
pos=0
found=False
while pos<len(alist) and not found:
if alist[pos]==item:
return ("找到了在第{}个位置".format(pos+1))
# return ('找到了在第%d个位置'%(pos+1))
else:
pos=pos+1
return '找不到该数'
list=[54,26,93,17,77,31,44,55,20,65]
print(sequen(list,54))
print(sequen(list,78))
![](https://i-blog.csdnimg.cn/blog_migrate/8790978722f820f1385c8a8c3f2538d7.png)