Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试在python中执行二进制搜索时出现TypeError_Python_Binary_Syntax Error_Typeerror - Fatal编程技术网

尝试在python中执行二进制搜索时出现TypeError

尝试在python中执行二进制搜索时出现TypeError,python,binary,syntax-error,typeerror,Python,Binary,Syntax Error,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:

我正试图编写一个二进制搜索,但无法使其工作。数组是预先确定的,程序正在搜索的值需要作为输入。到目前为止,我得到的是:

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")
MYVALUE=input
数组=[“3”、“5”、“2”、“9”、“1”]
最大=透镜(阵列)
中点=整数(最大值/2)
发现=错误
while(FOUND==False):
中点=整数(最大值/2)
如果MYVALUE>中点:
最小值=整数(中点)
最大=透镜(阵列)
elif int(MYVALUE)
这会不断返回以下错误,我确信它还有其他问题

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()
回溯(最近一次呼叫最后一次):
文件“/Users/auroraguild/Desktop/binary search.py”,第8行,在
如果MYVALUE>中点:
TypeError:无序类型:内置函数或方法()>int()
谢谢你

您想要:

MYVALUE = input()
不是:


您的binsearch看起来非常脏,有一个很好的例子:您不能对该列表进行二进制搜索,因为它不符合顺序。PEP8建议常量使用所有大写字母:
MYVALUE = input