Commit 2246f7f7 by BellCodeEditor

save project

parent 528ca2fe
Showing with 7 additions and 4 deletions
from random import choice()
from random import choice
alist = []
for i in range(1, 101):
alist.append(i)
......@@ -8,8 +8,10 @@ def binary_search(alist,num):
guess=0
low=0
high=len(alist)-1
while low>=high:
while low<=high:
mid=(low+high)//2
if alist[mid]==num:return mid
elif alist[mid]<num:
guess=alist[mid]
if guess==num:return mid
elif guess<num:low=mid+1
else:high=mid-1
print(binary_search(alist,num))
\ 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