[英]how to calculate the fixed monthly payment of credit card
如何繼續以下循環,直到找到mmp = 310
? 到目前為止,使用我的代碼,我能走的最遠是mmp = 240
。 您認為我還應該再有一個if
陳述嗎?
balance = 4213
annualInterestRate = 0.2
mir = annualInterestRate/12
monthlyPaymentRate = 0.04
rb = balance
mmp = 0
Month = 1
while Month <= 12:
print('Month:' + str(Month))
mmp = mmp + 10
print('Minimum monthly payment:' + str(mmp))
ub = rb - mmp
rb = round(ub + (annualInterestRate/12 * ub), 2)
Month = Month + 1
print('Remaining balance:' + str(rb))
if rb > 0:
rb = balance
Month = 1
while Month <= 12:
print('Month:' + str(Month))
mmp = mmp + 10
print('Minimum monthly payment:' + str(mmp))
ub = rb - mmp
rb = round(ub + (annualInterestRate/12 * ub), 2)
Month = Month + 1
print('Remaining balance:' + str(rb))
else:
print('Lowest Payment:' + str(mmp)
如果您只是想達到該數字,則可以使用while mmp < 310:
代替while Month <= 12:
while mmp < 310:
或while rb > 0:
如果要繼續循環直到所有費用都支付完畢。
如果需要循環數月(順便說一句, 如果您提到您的問題是家庭作業 , 通常在這里受到贊賞 ),則可以添加數年的外部循環:
year = 1
while rb > 0:
month = 1
while month <= 12:
# do stuff
month = month + 1
year = year + 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.