擅长:python、mysql、java
<p>我想这就是你要找的程序:</p>
<pre><code>balance = 500
annualInterestRate = .5
checkBalance = balance
monthlyFixedPayment = 10
count = 0
while checkBalance > 0:
month = 0
while month <= 11 and checkBalance > 0:
count+=1
monthlyInterestRate = annualInterestRate/12.0
monthlyUnpaidBalance = checkBalance - monthlyFixedPayment
checkBalance = monthlyUnpaidBalance - (monthlyInterestRate * monthlyUnpaidBalance)
print "\t"+str(checkBalance)
month+=1
print checkBalance
print "lowest amount: "
print count*monthlyFixedPayment+checkBalance
</code></pre>
<p>我留下了print语句,这样您就可以看到每次迭代中发生了什么。在</p>
<p>我在你的代码中发现了一些问题:</p>
<p>1)您正在执行一个<code>monthlyFixedPayment += 10</code>更改固定付款方式。你不应该根据你的问题定义改变固定付款。在</p>
<p>2)您在外部<code>while</code>循环的每个迭代中执行<code>checkBalance = balance</code>。这导致重置计算值。在</p>
<p>3)我引入了一个count变量来检查这些破坏发生了多少次,因为month在每次迭代中都会被重置。在</p>