python递归 - 重用函数输出

时间:2018-02-16 05:19:52

标签: python

我需要运行calc(a,b) 10次,但是在第一次迭代之后,我想传递它的输出,这是一个元组作为参数。

def test(a,b, count = 1):
    if count == 10:
        return
    cr = calc(a,b)
    return test(cr[0],cr[1], count+1)

print(test(10,4))返回无

1 个答案:

答案 0 :(得分:1)

它返回none,因为你没有返回任何东西 添加return cr,确保在尝试返回之前定义cr

def test(a,b, count = 1):
    cr = calc(a,b)
    if count == 10:
        return cr
    return test(cr[0],cr[1], count+1)