给定的问题:使用对分搜索找到12次还款后的每月最低还款额(略)。 假设利息是根据月末(当月付款之后)的余额按月计息。
annualInterestRate=.2
balance=320000
monthlyInterestrate=annualInterestRate/12
balance_initial=balance
lowerbound=(1/12)*balance
upperbound=balance*(1+monthlyInterestrate)**(12)/12
monthlyPayment=(upperbound+lowerbound)/2
while balance>-.00001 and balance<.00001:
for i in range(12):
balance=balance-monthlyPayment + (balance-monthlyPayment)*monthlyInterestrate
if balance>0:
lowerbound=monthlyPayment
if balance<0:
upperbound=monthlyPayment
print('Lowest Payment: ' + str(round(monthlyPayment, 2)))
使用我提供的数字(.2 AnnualInterestRate和32000余额,答案应该是“最低付款额:29157.09”
我得到的输出是29591.88
我凝视着屏幕至少一个小时,我完全不知道为什么我的答案与他们的答案不同。