fname = input("Enter file name: ")
if len(fname) == 0:
fname = 'mbox-short.txt'
fh = open(fname)
count = 0
tot = 0
ans = 0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
count = count + 1
num = float(line[21:])
tot = num + tot
ans = tot / count
print ("Average spam confidence:", ans)
4 Comments
If we enter mbox-short txt it showing no such file for above code can you help. Me with this
ReplyDeleteYou need to download mbox txt to your device.
DeleteWhy do you choose 21 in the row "num = float (line [21:])"?
ReplyDeleteI used line[19:] and it worked perfectly fine
ReplyDelete