Python 如何计算信用卡的每月固定付款
如何继续以下循环,直到找到Python 如何计算信用卡的每月固定付款,python,loops,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=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)
balance=4213
年利率=0.2
mir=年度利率/12
月付款率=0.04
rb=余额
mmp=0
月份=1
而第0个月:
rb=余额
月份=1
如果您想继续循环,直到所有费用都付清,请使用月份而不是月份0:
如果需要在几个月内循环(顺便说一句,它是),您可以在几年内添加一个外部循环:
year = 1
while rb > 0:
month = 1
while month <= 12:
# do stuff
month = month + 1
year = year + 1
year=1
rb>0时:
月份=1
是的,这是家庭作业的问题,我被棍子打得很厉害。还有一件事是它必须是1年
,因此基本上我必须计算mmp
在rb<0
的12个月内的值。