Get your own Python server Result Size: 625 x 565
x
 
def binarySearch(arr, targetVal):
  left = 0
  right = len(arr) - 1
  while left <= right:
    mid = (left + right) // 2
    if arr[mid] == targetVal:
      return mid
    if arr[mid] < targetVal:
      left = mid + 1
    else:
      right = mid - 1
  return -1
mylist = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
x = 11
result = binarySearch(mylist, x)
if result != -1:
  print("Found at index", result)
else:
  print("Not found")
Found at index 5