in the conditionals why don't you have to write high = data[middle_term] - 1. I understand why you do it in the actual if/else statements
data = [1,2,3,6,9,12,15,18,20]
def binary_search_algorthim(data,target):
low = 0
high = len(data) - 1
while low <= high:
middle_term = (low + high) // 2
if target == data[middle_term]:
return True
elif target < data[middle_term]:
high = middle_term - 1
print("high",high)
elif target > data[middle_term]:
low = middle_term + 1
print("low", low)
return False
ctrl-k. Formatting help ... more Formatting ... Formatting sandboxhigh,low, andmiddle_termare indices.data[middle_term]is a value at an index. you are keeping track of indices not values.high = data[middle_term] -1.