Can anyone help me explain this python code?
<blockquote>
  <p>7.2  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.</p>
  
  <p>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>
</blockquote>

<p>This is what I did and got the output but is it the right way to do it?:</p>

<pre><code>fname = raw_input("Enter file name: ")
fh = open(fname)
sum = 0
count = 0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
    line = line.replace("X-DSPAM-Confidence:","")
    line = line.strip()
    sum = sum + float(line)
    count = count + 1

avg = sum/count

print "Average spam confidence:",float(avg)
</code></pre>

<p>However, in few other sides, this one, and GitHub the code has been written differently. Can anyone explain it to me?</p>

<p>1)</p>

<pre><code>fname = raw_input("Enter file name: ")
fh = open(fname)
tot = 0.0
count = 0
for line in fh:
    if not line.startswith("X-DSPAM-Confidence:") : continue
    words = line.split()
    tot = tot + float(words[1])
    count = count + 1
print "Average spam confidence:", tot/count
</code></pre>

<p>What does <code>split()</code> do here? Remove blank spaces and print it on the next line right? So how does that help? And what will <code>float(words[1])</code> be then? Sorry is this sounds silly but this is my 3rd day into Python and I'm just trying to learn.</p>

<p>2) Lots others have used sum this way:</p>

<pre><code> a = line.split(':')
     sum = sum + float(a[1])
</code></pre>

<p>How does this work?</p>