Skip to content

Instantly share code, notes, and snippets.

@manichabba
Created July 23, 2016 21:29
Show Gist options
  • Save manichabba/7da787b84f36c58a45d768d44ae679bf to your computer and use it in GitHub Desktop.
Save manichabba/7da787b84f36c58a45d768d44ae679bf to your computer and use it in GitHub Desktop.
Python exercise 7.2
spam = 0.0
Count = 0
fname = raw_input("Enter file name: ")
try:
fh = open(fname)
except:
print "File cannot be opened:",fname
exit ()
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
spam = spam + float(line[line.find(" ")+1:])
Count = Count + 1
print "Average spam confidence:",spam / float(Count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment