擅长:python、mysql、java
<p>看起来你的价值观没有更新,因为你忘了每月更新余额!尝试在每个循环中更新一次<code>balance</code>变量,如下所示:</p>
<pre><code>while month < 13:
print "Month: " + str(month)
print "Minimum monthly payment: " + str(round(minimum_monthly_payment, 2))
print "Remaining balance: " + str(round(balance, 2))
balance = (balance - (balance*monthlyPaymentRate))*(1+(annualInterestRate/12))
month += 1
</code></pre>
<p>此外,为了使您的代码更易于阅读(并且更容易理解Python),您可以使用Python的内置列表结构,而不是使用自己的while循环:</p>
<pre><code>for month in range(1, 13):
print "Month: %d" % month
print "Minimum monthly payment: %d" % round(minimum_monthly_payment, 2)
print "Remaining balance: %d" % round(balance, 2)
balance = (balance - (balance * monthlyPaymentRate)) * (1 + (annualInterestRate / 12)
</code></pre>