def bsearch(array, target):
    min = 0
    max = len(array) - 1
    while max >= min:
        mid = (min + max) // 2
        if array[mid] == target:
            return mid 
        if array[mid] < target:
            min = mid + 1
        else:
            max = mid - 1
    return -1

array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
target = 3
print(bsearch(array, target))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: