title: Python programming error re: reading from files
body: <p>I'm taking an online class and we were assigned the following task:</p>
  
  <p>"Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form:
  X-DSPAM-Confidence:    0.8475
  Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below.
  You can download the sample data at <a href="http://www.pythonlearn.com/code/mbox-short.txt" rel="nofollow">http://www.pythonlearn.com/code/mbox-short.txt</a> when you are testing below enter mbox-short.txt as the file name."</p>
  
  <p>The desired output is: "Average spam confidence: 0.750718518519"</p>
  
  <p>Here is the code I've written: </p>
  
  <pre><code>fname = raw_input("Enter file name: ")
  fh = open(fname)
  inp = fh.read()
  for line in inp:
      if not line.strip().startswith("X-DSPAM-Confidence: 0.8475") : continue
  pos = line.find(':')
  num = float(line[pos+1:]) 
  total = float(num)
  count = float(total + 1)
  print 'Average spam confidence: ', float( total / count )
  </code></pre>
  
  <p>The output I get is: "Average spam confidence:  nan"</p>
  
  <p>What am I missing? </p>