blor
blor

Reputation: 25

python recursion - reusing function output

I need to run calc(a,b) 10 times but after the first iteration, I want to pass it's output which is a tuple as a parameter.

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)) returns None

Upvotes: 0

Views: 148

Answers (1)

Mitch
Mitch

Reputation: 3418

It returns none because you are not returning anything add, return cr, also ensure you define cr before you attempt to return it

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

Upvotes: 1

Related Questions