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>Here is a code snippet that suffices your work. I am reading the float values from the line with "X-DSPAM-Confidence:" and adding them and in the end, I am taking the mean. Also, since you are a beginner, I suggest to keep in mind that when you are dealing with division and you are expecting a float, either numerator or denominator should be float to give the answer in float. Since in the below code snippet, our number is float, we wont have that issue. </p>

<pre><code>fname = raw_input("Enter file name: ")
f = open(fname)
cnt = 0
mean_val = 0
for line in f:
    if not line.startswith("X-DSPAM-Confidence:") : continue
    mean_val += float(line.split(':')[1])
    cnt += 1
f.close()
mean_val /= cnt
print mean_val
</code></pre>

python