这个问题是针对 python 2.7 的。该问题要求编写一个程序,计算在 12 个月内还清信用卡余额所需的最低固定每月还款额。固定每月还款额是指每个月不会改变的单个数字,而是一个常数每月支付的金额。
在这个问题中,我们不会处理最低每月还款率。
以下变量包含如下所述的值: 余额 - 信用卡上的未偿余额 ananInterestRate - 年利率(小数)
该程序应打印出一行:将在 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)))
Run Code Online (Sandbox Code Playgroud)
有人可以帮我修复这个代码吗?对于给定的余额,最低付款是 310...我不知道如何得到这个...
小智 5
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33205 次 |
| 最近记录: |