python计算公式_Python如何计算这个公式?[等候接听]

为清楚起见:balance = 484

monthlyPaymentRate = 0.04

annualInterestRate = .2

for i in range(12):

paidoff = balance * monthlyPaymentRate

newinterest = (balance - paidoff) * annualInterestRate/12

balance = balance - paidoff + newinterest

print("Balance after", i+1, "months", round(balance,2));

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

得到:Balance after 1 months 472.38

Balance after 2 months 461.05

Balance after 3 months 449.98

Balance after 4 months 439.18

Balance after 5 months 428.64

Balance after 6 months 418.35

Balance after 7 months 408.31

Balance after 8 months 398.51

Balance after 9 months 388.95

Balance after 10 months 379.62

Balance after 11 months 370.5

Balance after 12 months 361.61

Remaining balance: 361.61

拆分计算允许这样的事情:>>> balance = 484

>>> totalpaid=0

>>> totalinterest=0

>>> monthlyPaymentRate = 0.04

>>> annualInterestRate = .2

>>> for i in range(12):

... paidoff = balance * monthlyPaymentRate

... newinterest = (balance - paidoff) * annualInterestRate/12

... balance = balance - paidoff + newinterest

... totalpaid = totalpaid + paidoff

... totalinterest = totalinterest + newinterest

...

>>> print("Remaining balance:", round(balance,2))

Remaining balance: 361.61

>>> print("Total amount paid off:", round(totalpaid,2))

Total amount paid off: 203.98

>>> print("Total interest accrued:", round(totalinterest,2))

Total interest accrued: 81.59

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值