I wrote the code below to complete the assignment:
fname = raw_input("Enter file name: ")
fh = open(fname)
total = 0
count = 0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
pos = line.find(':')
num = float(line[pos+1:])
for number in num:
total = total +num
count += 1
print 'Average spam confidence:', total/count
The system keep coming out error message reading that
float object is not iterable
I know that I made a mistake from for number in num:
And the correct answer is:
fname = raw_input("Enter file name: ")
fh = open(fname)
total = 0
count = 0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
pos = line.find(':')
num = float(line[pos+1:])
total = total +num
count += 1
print 'Average spam confidence:', total/count
but my question is : in the correct answer, is float object also iterable? Thanks for the help!!