Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这个Python年金函数哪里出了问题?_Python_Finance_Calculation_Annuity - Fatal编程技术网

这个Python年金函数哪里出了问题?

这个Python年金函数哪里出了问题?,python,finance,calculation,annuity,Python,Finance,Calculation,Annuity,我有一个python函数,在这里我创建了一个年金,它的价值每2年翻一番。我尝试了两种方法,第一种是递归的,但是我得到一个错误“比较中超过了最大递归深度”,或者类型为None(当我以annu(10000,40,0.1045)运行函数时) 第二个不涉及递归,但这给了我一个错误的答案: def inp(PMT, n,i): balance=0 FV1=0 FV2=0 k=PMT/i c=((1+i)**n)-1 FV=k*c for j

我有一个python函数,在这里我创建了一个年金,它的价值每2年翻一番。我尝试了两种方法,第一种是递归的,但是我得到一个错误“比较中超过了最大递归深度”,或者类型为None(当我以annu(10000,40,0.1045)运行函数时)

第二个不涉及递归,但这给了我一个错误的答案:

def inp(PMT, n,i):
    balance=0
    FV1=0
    FV2=0

    k=PMT/i

    c=((1+i)**n)-1

    FV=k*c

    for j in range(0,n):


        if j%2==1:
            FV=2*((FV)*(1+i)**(n-1))
            interest=balance*i

            balance=balance+interest + PMT

            FV1=FV1+balance
            print('FV1 is', FV1)
         else:
            FV2=2*((FV1)*(1+i)**(n-1))
            interest=balance*i

            balance=balance+interest + PMT

            FV2=FV2+balance
            print('FV2 is', FV2)
            FV=FV1+FV2
            print('inv_bal', FV)
            inv_bal=FV

如果我将其作为年度(10000,40,0.1045)运行,我希望得到大约4*10**9的答案

我投票将这个问题作为离题题结束,因为它是关于软件开发的。我肯定会将这个问题带到StackOverflow,但为了省去麻烦,只需逐行跟随递归函数,很快就会明白为什么要进入无限递归。我投票将这个问题作为离题b结束因为它是关于软件开发的。我肯定会把它带到StackOverflow,但为了省去麻烦,只需逐行遵循递归函数,就会很快明白为什么要进入无限递归。
def inp(PMT, n,i):
    balance=0
    FV1=0
    FV2=0

    k=PMT/i

    c=((1+i)**n)-1

    FV=k*c

    for j in range(0,n):


        if j%2==1:
            FV=2*((FV)*(1+i)**(n-1))
            interest=balance*i

            balance=balance+interest + PMT

            FV1=FV1+balance
            print('FV1 is', FV1)
         else:
            FV2=2*((FV1)*(1+i)**(n-1))
            interest=balance*i

            balance=balance+interest + PMT

            FV2=FV2+balance
            print('FV2 is', FV2)
            FV=FV1+FV2
            print('inv_bal', FV)
            inv_bal=FV