我的程序没有错,但是出现了错误提示

这个python提示我的错误我感觉我写的是对的,为什么会报错呢?
程序如下:

# 定义函数 binary_search 接受参数 list_sort, size, targer,并将查找结果返回
def binary_search(list_sort, size, targer):
    low = 0, high = size
    def dipole(low, high):
        if (low + high) % 2 == 0:
            return int((low+high)/2)
        else:
            return int(((low+high)-1)/2)
    while low <= high:
        mid = dipole(low, high)
        if list_sort[mid] < targer:
            high = mid - 1
        elif list_sort[mid] > targer:
            low = mid + 1
        else:
            return mid
try:
    print(binary_search([1,2,3,4,5,6,7,8,9], 9, 6))
except:
    print(-1)

报错的图片如下

img


有没有人解释一下

# 定义函数 binary_search 接受参数 list_sort, size, targer,并将查找结果返回
def binary_search(list_sort, size, targer):
    low = 0
    high = size
    mid=-1
    def dipole(low, high):
        if (low + high) % 2 == 0:
            return int((low+high)/2)
        else:
            return int(((low+high)-1)/2)
    while low <= high:
        mid = dipole(low, high)
        if list_sort[mid] < targer:
            low = mid + 1
        elif list_sort[mid] > targer:
            high = mid - 1
        else:
            return mid
try:
    print(binary_search([1,2,3,4,5,6,7,8,9], 9, 6))
except:
    print(-1)

low=mid+1和high=mid-1写反了,还有mid应该初始化为-1,不然没找到的话就是None

觉得有用的话采纳一下哈