Commit eb418ab8 by BellCodeEditor

save project

parent 773208ac
Showing with 13 additions and 9 deletions
...@@ -2,15 +2,19 @@ ...@@ -2,15 +2,19 @@
import random import random
for i in range(1,101): for i in range(1,101):
num_list.append(i) num_list.append(i)
low=0 num=random.choice(num_list)
high=len(num_list)-1
num=20
while low>hige: def binary_search(alist,num):
mid = (low+high) // 2 low=0
if mid == num: high=len(num_list)-1
print("找到了") while low<=high:
mid = low+high // 2
guess=num[mid]
if mid == guess:
return mid
elif mid < num: elif mid < num:
low = mid+1 low = mid+1
else: else:
high = mid-1 high = mid-1
print(mid) result binary_search(i,num)
\ No newline at end of file \ 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