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)
这是我的家庭作业问题。该代码搜索一年内还清贷款所需的最低付款额。我的代码在运行时运行良好。它产生了正确的答案,但是当我在线提交时,它说答案不正确。有谁知道为什么?