Python simple interest calculation
<p>I am trying to calculate how much monthly payment in order to pay off a loan in 12 month. use $10 as incremental.</p>

<pre><code>Payment = 0
balance = float (1200)
interest = float (0.18)
MonthlyInt = interest/12.0

while balance &gt; 0 :

    Payment = Payment + 10
    month = 0
    while month &lt; 12 and balance &gt; 0:
        IntPay = balance* MonthlyInt
        balance += IntPay
        balance -= Payment
        month += 1
print Payment
</code></pre>

<p>The correct answer should be 110, why am I getting 60?</p>

<p>The main things generating the difference are: </p>

<ul>
<li>The balance should be reset to 1200 before looping through the 12 months again</li>
<li>The payment should be deducted from the balance before calculating the interest</li>
</ul>

<p>A couple smaller python things are:</p>

<ul>
<li><code>float()</code> isn't needed around numbers like <code>0.18</code>, it's already a float</li>
<li><code>1200.</code> would imply that the number is a float, so <code>float()</code> isn't needed</li>
</ul>

<p>Accounting for these things then:</p>

<pre><code>Payment = 0
interest = 0.18
MonthlyInt = interest/12.0
balance = 1200.

while balance &gt; 0 :

    Payment = Payment + 10
    month = 0
    balance = 1200.
    while month &lt; 12 and balance &gt; 0:
        balance -= Payment
        IntPay = balance* MonthlyInt
        balance += IntPay
        month += 1
print(Payment)
</code></pre>

<p>gives a result of <code>110</code>.</p>

python