def binary_search(li, targetValue):
low, high = 0, len[li] #error on this line
while low <= high:
mid = (high - low)/2
if li[mid] == targetValue:
return "we found it!"
elif li[mid] > targetValue:
low = mid - 1;
elif li[mid] < targetValue:
high = mid + 1;
print "search failure "
最近剛發佈了這個問題,但我的代碼仍然不起作用?'builtin_function_or_method'對象不可自訂
當len()是一個內置函數來計算一個對象的長度時,你不能寫'len [li]'。 –