title: Python: Reading a file and calculating sum and average
body: <p>The question is to read the file line by line and calculate and display the sum and average of all of the valid numbers in the file.  </p>
  
  <p>The text file is</p>
  
  <pre><code>contains text
  79.3
  56.15
  67
  6
  text again 
  57.86
  6
  37.863
  text again 
  456.675
  </code></pre>
  
  <p>That's all I have so far. </p>
  
  <pre><code>numbers = open('fileofnumbers.txt', 'r')
  
  line = file_contents.readline()
  
  numbers.close()
  
  try:
      sum = line + line
      line = file_contents.readline()
      print "The sum of the numbers is", sum
  
  
  except ValueError:
      print line
  </code></pre>