title: Calculate a running total during a for loop - Python
body: <p><strong>Edit: Below is my working code based on the feedback/answers I recieved.</strong></p>
  
  <p>This question stems from my previous question that came up while learning Python/CS using open courseware from MIT. --<a href="https://stackoverflow.com/questions/4990159/python-beginner-is-this-python-code-as-efficient-as-it-could-be">See my previous question here</a>-- </p>
  
  <p>I am using the following code to make a list of month payments and other things. However at the end of the loop I need to give a running total for the total amount that has been paid of the months.</p>
  
  <p><strong>Original Code</strong></p>
  
  <pre><code>balance = float(raw_input("Outstanding Balance: "))
  interestRate = float(raw_input("Interest Rate: "))
  minPayRate = float(raw_input("Minimum Monthly Payment Rate: "))
  
  for month in xrange(1, 12+1):
      interestPaid = round(interestRate / 12.0 * balance, 2)
      minPayment = round(minPayRate * balance, 2)
      principalPaid = round(minPayment - interestPaid, 2)
      remainingBalance = round(balance - principalPaid, 2)
  
  
      print 'Month: %d' % (month,)
      print 'Minimum monthly payment: %.2f' % (minPayment,)
      print 'Principle paid: %.2f' % (principalPaid,)
      print 'Remaining balance: %.2f' % (remainingBalance,)
  
      balance = remainingBalance
  
      if month in xrange(12, 12+1):
          print 'RESULTS'
          print 'Total amount paid: '
          print 'Remaining balance: %.2f' % (remainingBalance,)
  </code></pre>
  
  <p>The problem is that I have not been able to figure out how to keep a running total of the amounts paid. I tried adding <code>totalPaid = round(interestPaid + principalPaid, 2)</code> but that just led to a total for a single month, I cant seem to get it to keep that value for each month and then add them all up at the end to be printed out.</p>
  
  <p>Also I know that the resulting amount should be 1131.12</p>
  
  <p>I have found many examples of doing this when each value is know, via a list, but I cant seem to extrapolate that correctly. </p>
  
  <p><strong>Fixed Code</strong></p>
  
  <pre><code>balance = float(raw_input("Outstanding Balance: "))
  interestRate = float(raw_input("Interest Rate: "))
  minPayRate = float(raw_input("Minimum Monthly Payment Rate: "))
  totalPaid = 0
  
  for month in xrange(1, 12+1):
      interestPaid = round(interestRate / 12.0 * balance, 2)
      minPayment = round(minPayRate * balance, 2)
      principalPaid = round(minPayment - interestPaid, 2)
      remainingBalance = round(balance - principalPaid, 2)
      totalPaid += round(minPayment, 2)
  
      print 'Month: %d' % (month,)
      print 'Minimum monthly payment: %.2f' % (minPayment,)
      print 'Principle paid: %.2f' % (principalPaid,)
      print 'Remaining balance: %.2f' % (remainingBalance,)
  
      balance = remainingBalance
  
      if month in xrange(12, 12+1):
          print 'RESULTS'
          print 'Total amount paid: %.2f' % (totalPaid,)
          print 'Remaining balance: %.2f' % (remainingBalance,)
  </code></pre>