title: Using 'For Loop' to write data to a file
body: <p>I am trying to use 'for loop' to write to a file in python dynamically, but I do not know how to calculate to write dynamically. I would appreciate if I get some help on this.</p>
  <pre><code>   def earnings(name, age, salary):
          AnnualRate = 0.05
          outFile = open('yearly_earnings.txt', 'w')
          outFile.write('Prepared by: Amornchot Singh')
          outFile.write('Age Salary Total')
  
          n = 26
          for n in range(66):
  
  
          ageLimit = 65
          i = 26
          totalEarned = 0
          for i in range(ageLimit+1):
              totalEarned += salary * (1+AnnualRate)
  
          print('summary for ' +  name)
          print('Starting salary at age ' + age + ' was ' + salary)
          print('Salary increases were 5.0% per year')
          print('Total accumulated earnings by age 65 is {:,.2f}'.format(totalEarned))
  
          print(&quot;To view yearly data go to 'yearly_earnings.txt'&quot;)
          print(&quot;'Thank you for using the earnings() function.'&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/72Noo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/72Noo.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/ulToV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ulToV.png" alt="enter image description here" /></a></p>