这是python二进制搜索代码,当我运行时它不起作用。
# Binary Search
def BinarySearch(*args, key, size):
low = 0
high = size - 1
while low <= high:
mid = (low + high) / 2
if key < args[mid]:
high = mid - 1
else:
if key > args[mid]:
low = mid + 1
else:
return mid + 1
return -1
arraySize = 10
A = [num * 2 for num in range(10)]
print("Numbers in array are : ", A)
searchKey = input("Enter integer search key : ")
element = BinarySearch(A, searchKey, arraySize)
if element != -1:
print("Found value in element : ", element)
else:
print("Value not found.")
错误是这样的:
类型错误:二进制搜索()缺少2个必需的仅关键字参数:“键”和“大小”那么,它有什么问题?请帮忙:)
慕盖茨4494581
慕神8447489
相关分类