Commit ea35c77c by BellCodeEditor

save project

parent 8d90f5ea
Showing with 4 additions and 25 deletions
# 使用二分查找法,找出9和20在列表 message="000000"
import random for i in message:
aist=[] print()
for i in range(1,101): \ No newline at end of file
alist.append(i)
num=random.chice(alist)
def binary_sarch(alist,num):
low = 0
high = len(alist)-1
while low <=high:
mid = (low+high)//2
guess=num_list[mid]
if guess_num == num_list[mid]:
return did
elif guess_num<bingo_num:
low=mid+1
elif guess_num>bingo_num:
high=mid-1
return None
result = binary_sarch(alist,num)
print('老师给的数是',num)
print('它在列表里的索引:',result)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment