I am learning Python, need some pushing in the right direction
<p>I am trying to learn Python through Coursera, and have some questions about an assignment.</p>

<blockquote>
  <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:</p>

<pre><code>X-DSPAM-Confidence:    0.8475
</code></pre>
  
  <p>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. Do not use the <code>sum()</code> function or a variable named <code>sum</code> in your solution.</p>
</blockquote>

<p>My code so far is as follows:</p>

<pre><code>fname = raw_input("Enter file name: ")
f = open(fname)
for line in f:
    if not line.startswith("X-DSPAM-Confidence:") : continue
    print line   
print "Done"
</code></pre>

<p>I am a bit confused. Should I store each line I get into a file or variable or something and then extract the floating point values for each?
How should this be tackled in the simplest way since this is just the beginning of the course?</p>

<p>The reason not to use a variable named <code>sum</code> is because there is a function with the same name.</p>

<p>The assignment asks you to do the work of the <code>sum()</code> function explicitly.  You are on the right track with the <code>if not</code> line but might be more successful if you reverse the logic (like this: <code>if line.startswith</code> ...), then put the handling inside an indented block that follows.</p>

<p>The handling you need is to keep track of how many such lines you handle and the accumulated sum.  Use a term that is a synonym for <code>sum</code> that is not already a Python identifier.  Extract the float value from the end of <code>line</code> and then <code>&lt;your sum variable&gt; += float(the float from "line")</code>.</p>

<p>Don't forget to initialize both counter and accumulator before the loop.</p>

python