Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.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 为什么这个函数不返回任何东西?_Python_Python 3.x - Fatal编程技术网

Python 为什么这个函数不返回任何东西?

Python 为什么这个函数不返回任何东西?,python,python-3.x,Python,Python 3.x,我用Python3编写了以下函数 def nullstelle(f,a,b,counter=0,TOL=10 ** -4): counter = counter + 1 if counter <= 100: g = f((a + b)/2) if f(a) * g <= 0: b = (a + b)/2 else: a = (a + b)/2 if abs(a-b) <= 2*TOL: return

我用Python3编写了以下函数

def nullstelle(f,a,b,counter=0,TOL=10 ** -4):
counter = counter + 1
if counter <= 100:
    g = f((a + b)/2)
    if f(a) * g <= 0:
        b = (a + b)/2
    else:
        a = (a + b)/2
    if abs(a-b) <= 2*TOL:
        return (a,b)
    else:
        nullstelle(f,a,b,counter,TOL)
else:
    return (a,b)
它不返回任何内容。我真的不明白这怎么可能


如果这对你们来说是一个微不足道的问题,我很抱歉,但编程绝对不是我感兴趣的主要领域,我对它几乎一无所知。

我觉得这是一个重复的问题,但不能很快找到。问题是您没有返回递归调用的结果,因此如果必须递归,您会得到
None
。将该行更改为:

return nullstelle(f,a,b,counter,TOL)

嵌套的
还有什么
;你应该做什么?运行
nullstelle
而不返回任何内容?大概
nullstelle(f,a,b,counter,TOL)
应该是
返回nullstelle(f,a,b,counter,TOL)
return nullstelle(f,a,b,counter,TOL)