python递归重用函数outpu

2024-04-25 00:54:01 发布

您现在位置: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))返回None


Tags: testnone参数returnifdefcountcalc
1条回答
网友
1楼 · 发布于 2024-04-25 00:54:01

它不返回任何内容,因为您不返回任何内容 添加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)

相关问题 更多 >