尝试在python

时间:2015-11-02 01:31:11

标签: python binary syntax-error typeerror uncaught-typeerror

我试图编写二进制搜索并且无法使其工作。数组是预定的,程序搜索的值需要是输入。到目前为止我所拥有的是:

MYVALUE = input
ARRAY = ["3", "5", "2", "9", "1"]
MAX = len(ARRAY)
MIDPOINT = int(MAX/2)
FOUND = False
while (FOUND == False):
    MIDPOINT = int(MAX/2)
    if MYVALUE > MIDPOINT:
        MIN = int(MIDPOINT)
        MAX = len(ARRAY)
    elif int(MYVALUE) < int(MIDPOINT):
        MAX = int(MIDPOINT)
        MIN = 1
    elif int(MYVALUE) == int(MIDPOINT):
        print("Value found. Value is " + int(MIDPOINT))
    else:
        print("Value not found")

这会不断返回以下错误,并且我确定它还有其他问题。

Traceback (most recent call last):
  File "/Users/auroraguild/Desktop/binary search.py", line 8, in <module>
    if MYVALUE > MIDPOINT:
TypeError: unorderable types: builtin_function_or_method() > int()

谢谢!!!

1 个答案:

答案 0 :(得分:0)

你想:

MYVALUE = input

for item in hexcodes:
    hexcodes_array = []
    hexcodes_array.append(extract_number(item))