Andres G
Andres G

Reputation: 30

return statement not passing value

Total newbie here......The return statement in the following code is not passing the value calculated by the function. Does anyone has any ideas ?


def pagos(B,P,r,c):
    UB = (B-P)*(1+(r/12)) 

    if (c==12):
        print(UB) #This is to establish if UB is actually reaching return statement#
        return UB
    c +=1
    pagos(UB,P,r,c)

P=200
B=10000
r=0.2
c=0

R = pagos(B,P,r,c)

print("Answer :"+str(R))```

9472.628606761953                                                                                                                                                                  
Answer :None

Upvotes: 0

Views: 63

Answers (2)

realxie
realxie

Reputation: 109

You should return pagos(UB,P,r,c) for the recursive procedure.

Upvotes: -1

Netwave
Netwave

Reputation: 42678

You forgot to use return in the recursive call:

def pagos(B,P,r,c):
    UB = (B-P)*(1+(r/12)) 

    if (c==12):
        print(UB)
        return UB
    c +=1
    return pagos(UB,P,r,c)

Upvotes: 2

Related Questions