Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere is my loop going wrong?
    text
    copied!<p>The brief I've been given - "Now write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance within 12 months."</p> <p>In essence what I've done is far, is code up something that will take a base value (10 for example), take it away from the credit card balance (taking into account the interest), and if the total number of months it takes to put the balance into a negative (e.g. paid off) is above 12, it adds to the 'minmonth' (amount to be paid off per month) until the number of months is equal to is or below 12.</p> <p>What's happening instead is that it's now coming up with this and getting into a loop, and constantly going into the ''else', rather than only doing it once when the number of months is below 12. Excessively long for post - <a href="http://pastebin.com/yruGDKiP" rel="nofollow">http://pastebin.com/yruGDKiP</a></p> <p>Where am I going wrong? :/</p> <pre><code>balance = float(raw_input('Enter the outstanding balance on your creditcard: ')) interest = float(raw_input('Enter the annual credit card interest rate as a decimal: ')) startbalance = balance minmonth = 1000 months = 0 monthlyinterest = interest / 12 while(balance &gt; 0): balance = balance * (1 + monthlyinterest) - minmonth months = months + 1 if(months &gt; 12): months = 0 minmonth = minmonth + 10 balance = startbalance else: print 'RESULT!' print 'Total amount to pay per month would be' print minmonth print 'Total months to pay' print months </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload