0

如何继续以下循环,直到找到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)
4

1 回答 1

0

如果您只想达到该数字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
于 2013-02-22T10:17:59.360 回答