Commit 9731a10d by BellCodeEditor

save project

parent 40f0e129
Showing with 4 additions and 4 deletions
...@@ -15,5 +15,5 @@ def bin_search(alist,num): ...@@ -15,5 +15,5 @@ def bin_search(alist,num):
higt=mid-1; higt=mid-1;
return None; return None;
result=bin_search(num_list,20); result=bin_search(num_list,100);
print("索引是:",result); print("索引是:",result);
\ No newline at end of file
# 什么都没有输出,说明不在列表里 # 什么都没有输出,说明不在列表里
bingo_num = 20 # 要查找的数:20 bingo_num = 3 # 要查找的数:20
num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21] num_list = [1, 3, 5, 8, 11, 15, 17, 18, 20, 21]
low = 0 low = 0
high = len(num_list)-1 high = len(num_list)-1
...@@ -14,4 +14,4 @@ while low <= high: ...@@ -14,4 +14,4 @@ while low <= high:
elif guess_num < bingo_num: elif guess_num < bingo_num:
low = mid+1 low = mid+1
elif guess_num > bingo_num: elif guess_num > bingo_num:
high = mid-1 high = mid-1
\ No newline at end of file
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