1
我的代碼給出正確的結果,除了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))
而*爲什麼*是360不正確?計算結果是什麼,你能爲我們解決這個問題嗎? – 2013-02-25 16:47:59
發佈時,請確保將您的代碼放入代碼塊(這是「{}」按鈕)。我是第二個爲你解決它的人。 – n00dle 2013-02-25 16:50:12
根據程序的回答是370,但它應該是360 – user1437027 2013-02-25 16:51:00