def BinarySearch(data_of_xyz, search_key):
low_indx = 0
hig_indx = len(data_of_xyz) -1
found = False
while low_indx<=hig_indx and not found:
mid_indx = (low_indx + hig_indx) // 2
if search_key == data_of_xyz[mid_indx]:
found = True
elif search_key > data_of_xyz[mid_indx]:
low_indx = mid_indx + 1
else:
hig_indx = mid_indx - 1
if found == True:
print("Your search key is at position: ")
else:
print("Your key is not found: ")
data_of_xyz = [13, 24, 32, 35, 78]
data_of_xyz.sort()
print(data_of_xyz)
search_key = int(input("Enter the required key: "))
BinarySearch(data_of_xyz,search_key)
OUTPUT
Enter the required key: 35
Your search key is at position:
, если вы видите, что он не показывает 35 позиций из списка!