如果一個人每個月只支付信用卡公司要求的最低每月支付,請編寫一個程序計算一年後的信用卡餘額。計算信用餘額的計劃
我試圖寫一個程序,將打印期末餘額左手交一年後
balance = 4213
annualInterestRate = 0.2
monthlyPaymentRate = 0.04
month = 1
new_balance = (balance - (balance*monthlyPaymentRate))*(1+(annualInterestRate/12))
while month < 13:
print "Month: " + str(month)
print "Minimum monthly payment: " + str(round(minimum_monthly_payment, 2))
print "Remaining balance: " + str(round(new_balance, 2))
month += 1
我的輸出顯示這一點:
Month: 1
Minimum monthly payment: 168.52
Remaining balance: 4111.89
Month: 2
Minimum monthly payment: 168.52
Remaining balance: 4111.89
Month: 3
Minimum monthly payment: 168.52
Remaining balance: 4111.89
但我應該得到的東西是這樣的:
Month: 1
Minimum monthly payment: 168.52
Remaining balance: 4111.89
Month: 2
Minimum monthly payment: 164.48
Remaining balance: 4013.2
Month: 3
Minimum monthly payment: 160.53
Remaining balance: 3916.8
非常感謝。我剛剛在while循環中觀看了一段視頻,只是看到了我的錯誤。我沒有把餘額作爲變量放入循環中,並且在循環之後沒有修改......謝謝。 :) – Contempt
@ user1692479很高興幫助。 :)如果回答幫助你,那麼你可以通過檢查答案左邊的勾號來接受它。 –