递归小例子的python语言实现

问题:

假设你每年初往银行账户中1000元钱,银行的年利率为4.7%。

一年后,你的账户余额为:

1000 * ( 1 + 0.047) = 1047 元

第二年初你又存入1000元,则两年后账户余额为:

(1047 + 1000) * ( 1 + 0.047) = 2143.209 元

以此类推,第10年年末,你的账户上有多少余额?

python代码:

def f(n):
    if n==1:
        return 1047
    return (f(n-1)+1000)*1.047
    print f(n)
原文地址:https://www.cnblogs.com/berryfad/p/4164036.html