我的付款计算器出了什么问题?

时间:2013-10-31 18:08:24

标签: 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)

这是我的家庭作业问题。该代码搜索在一年内偿还贷款所需的最低金额。 我运行它时,我的代码工作正常。它产生了正确的答案,但是当我在线提交时,它说答案是错误的。有谁知道为什么?

0 个答案:

没有答案