Commit dab52de5 by BellCodeEditor

save project

parent 02020452
Showing with 16 additions and 2 deletions
from random import randint,choice
# 使用二分查找法,找出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]
index = 0
for i in range(101,175,randint(0,4)):
num_list.append(i)
index = 0
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
def reast():
'''
reast low and high.
'''
global low,high
low,high = 0,len(num_list) - 1
while index < len(bingo_num):
low,high = 0,len(num_list) - 1
reast()
while low <= high:
mid = (low + high)
guess_num = num_list[mid]
......@@ -19,3 +31,4 @@ while index < len(bingo_num):
elif guess_num > bingo_num[index]:
high = mid - 1
index += 1
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