在问题中使用测试用例后,我得到了 inf 结果
balance = 42
annualInterestRate = 0.2
monthlyPaymentRate = 0.04
def AfterBalance(balance,annualInterestRate,monthlyPaymentRate):
monthlyInterestRate = annualInterestRate / 12.0
for i in range(12):
monthlyPaymentRate = monthlyPaymentRate * balance
monthlyUnpaid = balance - monthlyPaymentRate
balance = monthlyUnpaid + monthlyInterestRate * monthlyUnpaid
return round(balance,2)
LastBalance = AfterBalance(balance,annualInterestRate,monthlyPaymentRate)
print("Remaining balance", LastBalance)
我预计案件结果为 31.38 我只需要知道 inf 结果是如何形成的。 感谢您的帮助。
balance = 42
annualInterestRate = 0.2
monthlyPaymentRate = 0.04
def AfterBalance(balance, annualInterestRate, monthlyPaymentRate):
monthlyInterestRate = annualInterestRate / 12.0
for i in range(12):
monthlyPayment = monthlyPaymentRate * balance
monthlyUnpaid = balance - monthlyPayment
balance = monthlyUnpaid + monthlyInterestRate * monthlyUnpaid
return round(balance, 2)
LastBalance = AfterBalance(balance, annualInterestRate, monthlyPaymentRate)
print("Remaining balance", LastBalance)
输出:
Remaining balance 31.38