Tell us what’s happening:
I thought it was simple, but I keep getting an error message saying the return should get: “, ‘Value not found’”. Yet, this is exactly what I see in the console, so what would be wrong?
Your code so far
def binary_search(search_list, value):
path_to_target = []
low = 0
high = len(search_list) - 1
while low <= high:
mid = (low + high) // 2
value_at_middle = search_list[mid]
path_to_target.append(value_at_middle)
if value == value_at_middle:
return path_to_target
elif value > value_at_middle:
low = mid + 1
else:
high = mid - 1
# User Editable Region
return f"{[]}, 'Value not found'"
# User Editable Region
print(binary_search([1, 2, 3, 4, 5], 3))
print(binary_search([1, 2, 3, 4, 5, 9], 4))
print(binary_search([1, 3, 5, 9, 14, 22], 10))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3.1 Safari/605.1.15
Challenge Information:
Implement the Binary Search Algorithm - Step 15