这个问题是针对 python 2.7 的。该问题要求编写一个程序来计算在 12 个月内还清信用卡余额所需的最低固定月供。通过固定月供,我们指的是一个每月不变的单一数字,而是一个常数每月支付的金额。
在这个问题中,我们不会处理最低每月支付率。
以下变量包含如下所述的值: balance - 信用卡上的未结余额 annualInterestRate - 小数形式的年利率
该程序应打印出一行:将在 1 年内还清所有债务的最低月付款额。
假设根据月末余额(当月付款后)按月复利。每月付款必须是 10 美元的倍数,并且所有月份都相同。请注意,使用此支付方案,余额可能会变为负值,这是可以的。所需数学的摘要如下:
月利率=(年利率)/12 每月更新的余额 =(之前的余额 - 每月最低还款额)x(1 + 月利率)
我想出了一个问题的代码;但是,我反复遇到无限循环。
b = balance = 3329
air = annualInterestRate = 0.2
monthlyInterestRate = (air/12)
mmp = minimumMonthlyPayment = (balance * monthlyInterestRate)
month = 0
while month <= 12:
b = ((b - mmp) * (1 + (air/12)))
month = 1 + month
if b <= 0 and month == 12:
break
elif b > 0 and month == 12:
b = balance
month = 0
mmp = minimumMonthlyPayment + 10.00
print str('Lowest Payment: ' + str(round(mmp, 2)))
有人可以帮我修复这段代码吗?对于给定的余额,最低付款是 310...我不确定如何获得此...
请您参考如下方法:
monthlyInterestRate = annualInterestRate/12
monthlyPayment = 0
newbalance = balance
while newbalance > 0:
monthlyPayment += 10
newbalance = balance
month = 1
while month <= 12 and newbalance > 0:
newbalance -= monthlyPayment
interest = monthlyInterestRate * newbalance
newbalance += interest
month += 1
newbalance = round(newbalance,2)
