title: Averages for multiple lines of text file, Python 3
body: <p>I have a .txt file with lines of grades that I need to calculate the averages for. I've really hit a wall with figuring out how to get the averaging function to iterate every line of the text file. For some reason I get a syntax error if there is an odd amount of lines. And when the line amount is even python returns every <strong>other</strong> line. Heres my code.</p>
  
  <pre><code>with open('grades.txt','r') as source:
  def toNumbers():
      global t
      g = source.readline()
      t = eval(g)
  def sumList(variable):
      a = sum(variable)/len(variable)
      print('average:', round(a))
  for lines in source:
      toNumbers()
      sumList(t)
  </code></pre>
  
  <p>Thanks.</p>