File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ '''Write a program that prompts for a file nam, then opens the file & reads through the file looking
2+ for lines of the form:
3+ X-DSPAM-Confidence: 0.8475
4+ Count these lines & extract the floating point values from each of the lines &
5+ compute the average of those values & produce an output.
6+ FILE: mbox-short.txt
7+ WEB LINK: http://www.py4e.com/code3/mbox-short.txt'''
8+
9+ fname = input ('Enter the file name: ' )
10+ x = open (fname )
11+ avg = 0.0
12+ count = 1
13+ tot = 0.0
14+ for line in x :
15+ line = line .rstrip ()
16+ if line .startswith ('X-DSPAM-Confidence:' ):
17+ count += 1
18+ col_pos = line .find (':' )
19+ val = line [col_pos + 1 :]
20+ val = val .strip ()
21+ float_val = float (val )
22+ tot += float_val
23+
24+ avg = tot / count
25+ print ('Average spam confidence:' ,avg )
You can’t perform that action at this time.
0 commit comments