Skip to content

Commit f653d7f

Browse files
Create Assignment 7.2
1 parent a1b06e3 commit f653d7f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

PFE/PDS/Assignment 7.2

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
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:
3+
X-DSPAM-Confidence: 0.8475
4+
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. Do not use the sum() function or a variable named sum in your solution.
5+
You can download the sample data at mbox-short.txt
6+
"""
7+
8+
# Use the file name mbox-short.txt as the file name
9+
fname = input("Enter file name: ")
10+
fh = open(fname)
11+
total=0
12+
count=0
13+
for line in fh:
14+
if line.startswith("X-DSPAM-Confidence:") :
15+
x=line.find(' ')
16+
number=float(line[x:])
17+
total=number+total
18+
count=count+1
19+
20+
print("Average spam confidence:",total/count)
21+
22+
23+
"""
24+
Desired Output:
25+
Average spam confidence: 0.750718518519
26+
27+
"""

0 commit comments

Comments
 (0)