Python中文
首页
教程
问答
标签
搜索
登录
注册
计算credi余额的程序
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>如果一个人每月只支付信用卡公司要求的最低月供,写一个程序来计算一年后的信用卡余额。</p> <p>我想写一个程序,打印出一年后的最后余额</p> <pre><code>balance = 4213 annualInterestRate = 0.2 monthlyPaymentRate = 0.04 month = 1 new_balance = (balance - (balance*monthlyPaymentRate))*(1+(annualInterestRate/12)) while month < 13: print "Month: " + str(month) print "Minimum monthly payment: " + str(round(minimum_monthly_payment, 2)) print "Remaining balance: " + str(round(new_balance, 2)) month += 1 </code></pre> <p>我的输出显示:</p> <pre><code>Month: 1 Minimum monthly payment: 168.52 Remaining balance: 4111.89 Month: 2 Minimum monthly payment: 168.52 Remaining balance: 4111.89 Month: 3 Minimum monthly payment: 168.52 Remaining balance: 4111.89 </code></pre> <p>但我应该得到这样的东西:</p> <pre><code>Month: 1 Minimum monthly payment: 168.52 Remaining balance: 4111.89 Month: 2 Minimum monthly payment: 164.48 Remaining balance: 4013.2 Month: 3 Minimum monthly payment: 160.53 Remaining balance: 3916.8 </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你做了3次同一行:<code>new_balance = (balance - (balance*monthlyPaymentRate))*(1+(annualInterestRate/12))</code></p> <p>这里没有任何variabel,它将在每次while循环后更新。 您应该更新<code>balance</code>,以便每次都得到一个较低的数字。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python中两个字典的交集
1 回答
python中两个字符串上的异或操作数?
3 回答
Python中两个字符串中的类似句子
8 回答
Python中两个字符串之间的Hamming距离
4 回答
python中两个字符串之间的匹配模式
10 回答
python中两个字符串之间的按位或
1 回答
python中两个字符串之间的数据(字节)切片
2 回答
python中两个字符串之间的模式
10 回答
python中两个字符串作为子字符串的区别
1 回答
Python中两个字符串元组的比较
5 回答
Python中两个字符串列表中的公共字符串
8 回答
python中两个字符串的Anagram测试
3 回答
Python中两个字符串的正则匹配
4 回答
python中两个字符串的笛卡尔乘积
7 回答
Python中两个字符串相似性的比较
3 回答
python中两个字符串语义相似度的求法
8 回答
Python中两个字符置换成固定长度的字符串,每个字符的数目相等
5 回答
Python中两个对数方程之间的插值和平滑数据
1 回答
Python中两个对象之间的And/Or运算符
3 回答
python中两个嵌套字典中相似键的和值
6 回答