0% found this document useful (0 votes)
81 views

Assign7 2autograder

The document describes a program that prompts the user for a file name, opens that file, counts the number of lines starting with "X-DSPAM-Confidence:", extracts the floating point values from those lines and calculates the average. It provides sample output and notes that the sample data file can be downloaded from the given URL.

Uploaded by

KarthikPillai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Assign7 2autograder

The document describes a program that prompts the user for a file name, opens that file, counts the number of lines starting with "X-DSPAM-Confidence:", extracts the floating point values from those lines and calculates the average. It provides sample output and notes that the sample data file can be downloaded from the given URL.

Uploaded by

KarthikPillai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

'''

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:
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 http://www.pythonlearn.com/code/mbox-short.txt
when you are testing below enter mbox-short.txt
as the file name.
'''

fname=raw_input("Enter the file name:")


fhand=open(fname)
count=0
for line in fhand:
#line=line.strip()
if not line.startswith("X-DSPAM-Confidence: 0.8475"):
continue
count=count+1
print 'Average spam confidence: ', float( total / count )

You might also like