我的付款计算器怎么了?

2024-04-23 20:33:10 发布

您现在位置:Python中文网/ 问答频道 /正文

balance = 999999
annualInterestRate = 0.18

monthlyInterestRate = annualInterestRate/12.0

epsilon = .01

low = balance/12.0
high = (balance * (1+monthlyInterestRate)**12)/12.0

guess = (high+low)/2.0
print 'first guess: ', guess
x = balance

while abs(x) > epsilon:
    x= balance
    for month in range(12):
        x = (x - guess) * (1 + monthlyInterestRate)
    if x < 0:
        high = guess
        guess = (high+low)/2.0
    elif x > 0:
        low = guess
        guess = (high+low)/2.0
print 'Lowest Payment: ', round(guess,2)

这是我做作业时遇到的问题。代码搜索一年内还清贷款所需的最低付款额。 我的代码在运行时运行良好。它产生了正确的答案,但当我提交网上,它说的答案是不正确的。有人知道为什么吗?你知道吗


Tags: 答案代码forabslowfirstprintbalance