Skip to content

Instantly share code, notes, and snippets.

@hareom284
Created July 22, 2020 15:27
Show Gist options
  • Save hareom284/e31ea90df6b9f70d68e5f88c1ead8622 to your computer and use it in GitHub Desktop.
Save hareom284/e31ea90df6b9f70d68e5f88c1ead8622 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. Do not use the sum() function or a va…
fname = input("Enter file name: ")
fh = open(fname)
count = 0
total = 0.0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
count = count + 1
line = line[20:]
line = float(line)
total = total+line
print("Average spam confidence:",total/count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment