Commit dab52de5 by BellCodeEditor

save project

parent 02020452
Showing with 17 additions and 4 deletions
from random import randint,choice
# 使用二分查找法,找出9和20在列表里面的索引 # 使用二分查找法,找出9和20在列表里面的索引
num_list = [1, 3, 5, 8, 9, 11, 15, 17, 18, 20, 21, 36, 44, 55, 57, 67, 74, 76, 84, 91, 93, 98, 100] num_list = [1, 3, 5, 8, 9, 11, 15, 17, 18, 20, 21, 36, 44, 55, 57, 67, 74, 76, 84, 91, 93, 98, 100]
index = 0 for i in range(101,175,randint(0,4)):
num_list.append(i)
index = 0
bingo_num = [9, 20, 55, 76, 98] bingo_num = [9, 20, 55, 76, 98]
for i in range(3):
bingo_num.append(choice(num_list))
low,high = 0,len(num_list) - 1 low,high = 0,len(num_list) - 1
def reast():
'''
reast low and high.
'''
global low,high
low,high = 0,len(num_list) - 1
while index < len(bingo_num): while index < len(bingo_num):
low,high = 0,len(num_list) - 1 reast()
while low <= high: while low <= high:
mid = (low + high) mid = (low + high)
guess_num = num_list[mid] guess_num = num_list[mid]
...@@ -18,4 +30,5 @@ while index < len(bingo_num): ...@@ -18,4 +30,5 @@ while index < len(bingo_num):
low = mid + 1 low = mid + 1
elif guess_num > bingo_num[index]: elif guess_num > bingo_num[index]:
high = mid - 1 high = mid - 1
index += 1 index += 1
\ No newline at end of file print("列表是:%a,要找的数是:%s"%(num_list,str(bingo_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