title: Using Excel like solver in Python or SQL
body: <p>Here is a simple calculation that I do in Excel. I will like to know if it can be done python or any other language. </p>
  
  <pre><code>Loan amount 7692
  Period : 12 months
  Rate of interest 18 Per Annum
  The formula in the B2 cell is =A1*18/100/12
  The formula in the A2 cells is =A1+B2-C2
  </code></pre>
  
  <p>The column C is tentative amount the borrower may need to repay each month. All other cells next to C2 simply points to the first installment of 200. After using the solver as shown in the following image, I get the correct installment of 705.20 in the C column. </p>
  
  <p><a href="https://i.stack.imgur.com/elmP8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/elmP8.png" alt="excel goal seak"></a></p>
  
  <p>I will like to know if this calculation can be done using any scripting language like python (or SQL)</p>
  
  <p>Here is how the final version looks like...</p>
  
  <p><a href="https://i.stack.imgur.com/M0t9I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M0t9I.png" alt="enter image description here"></a></p>
  
  <p>I tried something like this, but it does not exit the loop and prints all combinations.</p>
  
  <pre><code>loan_amount= 7692
  interest = 18
  months =12
  
  for rg in range(700, 710):
      for i in range(months):
          x = loan_amount * interest / 100 / 12
          y = loan_amount + x - rg
          if x &lt; 0: 
              print rg, i
              exit
          else:
              loan_amount = y
  </code></pre>