xfile=open("mbox-short.txt") numlist=list() sum, count =0,0 for line in xfile: line=line.rstrip() if line.startswith("X-DSPAM-Confidence:"): words=line.split() num= float(words) sum=sum+num count=count+1 numlist.append(num) print sum/count print sum(numlist)/len(numlist)
This program returns the error, due to the last line
Traceback (most recent call last): File "C:\Users\rahulgenesis\OneDrive\notes\Python Notes\files\8 average of numbers using list.py", line 13, in <module> print sum(numlist)/len(numlist) TypeError: 'float' object is not callable
The objective of the program is to calculate the average of the extracted elements (spam score) from a mail box. I am trying to do it using list, after storing the elements inside the list. I am kinda feeling that this error is due to the fact that all the elements in the list are not of the same type...?