Commit 498cb689 by BellCodeEditor

save project

parent 91fc1829
Showing with 20 additions and 4 deletions
...@@ -5,11 +5,27 @@ high=len(num_list)-1 ...@@ -5,11 +5,27 @@ high=len(num_list)-1
while True: while True:
mid=(low+high)//2 mid=(low+high)//2
guess=num_list[mid] guess=num_list[mid]
if guess==17: if guess==20:
print("找到了!") print("找到了!")
print(str(mid)) print(str(mid))
break break
elif guess<17: elif guess<20:
low=mid+1 low=mid+1
else: else:
high=mid-1 high=mid-1
\ No newline at end of file low=0
high=len(num_list)-1
while True:
mid=(low+high)//2
guess=num_list[mid]
if guess==9:
print("找到了!")
print(str(mid))
break
elif guess<9:
low=mid+1
else:
high=mid-1
if high <= low:
print("没有这个数!")
break
\ 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