title: How to find average of a column in a txt file in Python?
body: <p>Practicing some Python and am trying to solve an a problem that asks to get the average age of students in a text file. Ex. of the .txt file shown below.</p>
  
  <pre><code>   Sam, 23
     Jack 20
     Tara 19
     Stacy 22
  </code></pre>
  
  <p>Normally I would re-trace my steps with an error message, but my output is just a 0. I'm not sure if using read instead of readlines is correct either.</p>
  
  <pre><code>def sumNums():
      infile = open('student_age.txt', 'r')
      fileContents = infile.read()
      infile.close
  
      count= 0
  
      for lines in fileContents.split(','):
          if lines.isdigit():
              count += lines
  
      print(sum(count) / len(lines))
  </code></pre>
  
  <p>Actual output should be 21 since 84/4=21 but I am getting 0</p>