From e32789e5a323a8741add99f3086ddc88da68bbe4 Mon Sep 17 00:00:00 2001 From: Krishna R <58383978+Krishna-Ravi@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:10:02 +0530 Subject: [PATCH] Update Assignment 7.2.py~ This is another easier way to get the required output. --- week7/Assignment 7.2.py~ | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/week7/Assignment 7.2.py~ b/week7/Assignment 7.2.py~ index d43d306..a8bf92f 100644 --- a/week7/Assignment 7.2.py~ +++ b/week7/Assignment 7.2.py~ @@ -12,16 +12,18 @@ You can download the sample data at http://www.pythonlearn.com/code/mbox-short.t #Average spam confidence: 0.750718518519 # Use the file name mbox-short.txt as the file name -fname = raw_input("Enter file name: ") +fname = input("Enter file name: ") fh = open(fname) -l = [] +c = 0 +lst = [] +total = 0.0 for line in fh: if not line.startswith("X-DSPAM-Confidence:") : continue - ll = line.split() - for i in ll: - try: - u = float(i) - l.append(u) - except: - pass -print "Average spam confidence:",sum(l)/len(l) + f = (line.split()) + c+=1 + lst.append(f[1]) + +for i in lst: + total +=float(i) + +print("Average spam confidence:",total/len(lst))