lst = []
for i in range(1,5000,3):
lst.append(i)
num = int(input('请输入一个数:'))
left = 0
right = len(lst) - 1
count = 0
while left <= right:
count += 1
mid = (right + left) // 2
if num < lst[mid]:
right = mid - 1
elif num > lst[mid]:
left = mid + 1
else:
print('find it')
break
else:
print('can not find it')
print(count)
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
lst = [] for i in range(1,5000,3): lst.append(i) num = int(input('请输入一个数:')) left = 0 right = len(lst) - 1 count = 0 while left <= right: count += 1 mid = (right + left) // 2 if num < lst[mid]: right = mid - 1 elif num > lst[mid]: left = mid + 1 else: print('find it') break else: print('can not find it') print(count)