python for 循环的结果相加_在Python中的每次迭代之后添加for循环的结果

我开始学习编码,从Python开始。在我的Python课程中,我遇到了以下问题:Write a program to calculate the credit card balance after one year if

a person only pays the minimum monthly payment required by the credit

card company each month.

The following variables contain values as described below:

balance - the outstanding balance on the credit card

annualInterestRate - annual interest rate as a decimal

monthlyPaymentRate - minimum monthly payment rate as a decimal

For each month, calculate statements on the monthly payment and

remaining balance, and print to screen something of the format:

Month: 1

Minimum monthly payment: 96.0

Remaining balance: 4784.0

(我把那部分搞定了)Finally, print out the total amount paid that year and the remaining balance at the end of the year in the format:

Total paid: 96.0

Remaining balance: 4784.0

(这是总付费的一部分,我经过许多小时的尝试和搜索无法解决)

所以我需要做的是:把每月最低付款额的所有结果加起来,得到所付的总额。在

这是我的代码:def creditPayment(balance, annuelInterestRate, monthlyPaymentRate):

for month in range(1, 13):

monthlyInterestRate = annuelInterestRate/ 12.0

minimumMonthlyPayment = monthlyPaymentRate * balance

monthlyUnpaidBalance = balance - minimumMonthlyPayment

balance = monthlyUnpaidBalance + (monthlyInterestRate * monthlyUnpaidBalance)

totalPaid = sum((minimumMonthlyPayment) for _ in range(0, 13))

print 'Month: ', month

print 'Minimum monthly payment: ', round(minimumMonthlyPayment, 2)

print 'Remaining balance: ', round(balance, 2)

print ' '

print 'Total paid: ', round(totalPaid, 2)

print 'Remaining balance: ', round(balance, 2)

print creditPayment(4213, 0.2, 0.04)

一切都很好,除了总支付额加起来只有最低月供第一值的12倍。我不能再好了。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值