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)
这是我做作业时遇到的问题。代码搜索一年内还清贷款所需的最低付款额。 我的代码在运行时运行良好。它产生了正确的答案,但当我提交网上,它说的答案是不正确的。有人知道为什么吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐