Created
August 16, 2015 04:25
-
-
Save KKarthikeya/472b419dcb8473d6ba3c to your computer and use it in GitHub Desktop.
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 h…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sum = 0.0 | |
count = 0 | |
fname = open(raw_input("Enter file name: ")) | |
for line in fname: | |
if not line.startswith("X-DSPAM-Confidence:") : continue | |
sum = sum + float(line[line.find(" ")+1:]) | |
count = count + 1 | |
print "Average spam confidence:",sum/float(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment