def search(data_set,find_num):
mid = len(data_set) /2
print mid
if len(data_set) == 1:
if data_set[mid] == find_num:
print (‘End start: ‘,find_num)
return
else:
print (‘NO NO NO:‘,find_num)
return
if data_set[mid] == find_num:
print (‘find start:‘,find_num)
return
elif data_set[mid] > find_num:
print (‘in left‘,data_set[:mid])
search(data_set[:mid],find_num)
elif data_set[mid] < find_num:
print (‘in right‘,data_set[mid:])
search(data_set[mid:],find_num)
if __name__ == ‘__main__‘:
data = range(1,20,3)
print (data)
find = input(‘num:‘)
search(data,find)
时间: 2024-10-21 19:58:05