如何计算固定的每月信用卡付款

时间:2013-02-22 10:07:05

标签: python loops

在找到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)

1 个答案:

答案 0 :(得分:0)

如果您只是想要达到该号码,则可以使用while Month <= 12:而不是while mmp < 310:。或者while rb > 0:如果你想继续循环,直到付清所有费用。

如果需要循环几个月(btw,它是generally appreciated here if you mention that your question is homework),你可以多年来添加一个外循环:

year = 1
while rb > 0:
    month = 1
    while month <= 12:
        # do stuff
        month = month + 1
    year = year + 1