擅长:python、mysql、java
<p>你算法中的问题是每月的付款是根据新的余额计算的。</p>
<p>关于Python代码的几点:</p>
<p>1-在python中编码时使用下划线而不是camelCase</p>
<p>2-打印时使用字符串格式而不是str()</p>
<p>3-比在这里更好的选择</p>
<p>4-不需要括号时,无需过度使用</p>
<pre><code>balance = 4213
annual_interest_rate = 0.2
monthly_payment_rate =0.04
monthly_interest_rate = annual_interest_rate / 12
monthly_payment = monthly_payment_rate * balance
new_balance= (balance - monthly_payment) * (1 + monthly_interest_rate)
for month in range(1, 13):
monthly_payment = monthly_payment_rate * balance
balance = (balance - monthly_payment) * (1 + monthly_interest_rate)
print('Month: %d \n Minimum monthly payment: %g \n Remaining balance: %g'\
% (month, round(monthly_payment, 2), round(balance,2)))
</code></pre>