我的代码给出了正确的结果,除了 balance=3926。最低付款:370,而应该是 360。程序应打印给定年利率的最低每月付款。给定初始余额,代码应在年底计算余额。我们正在尝试每月支付 10 美元的初始余额。如果年底还有余额,我们编写代码将余额重置为初始余额,将付款增加 10 美元,然后重试(使用相同的代码!)计算年末余额年,看看这个新的支付价值是否足够大
annualInterestRate = 0.2
balance = 3926
monthlyinterestrate = annualInterestRate/12.0
remainingBalance = balance
month = 1
total = 0
payment = 10
def CheckMinimumPayment(payment,balance):
"Checking if payment is in correct balance"
while(payment*12 < balance):
payment += 10
return payment
payment = CheckMinimumPayment(payment,balance)
while(month <= 12):
remainingBalance = remainingBalance - payment + (annualInterestRate / 12.0) * (remainingBalance - payment)
month += 1
total += payment
payment = CheckMinimumPayment(payment,total+remainingBalance)
print("Lowest Payment: " + str(payment))