On 15/06/13 06:22, Patrick Williams wrote:
Hi so I am making a bit of code to extract a bit of numbers data from a file and then find the average of that data, however while I can get the code to extract each specific piece of data I need, I can't seem to get the numbers to add separately so I can get a proper average. My sum1 variable seems to only take the last bit of data entered.
for line in fhand: if line.startswith('X-DSPAM-Confidence:'): count=count+1 colpos=line.find(':') zpos=line.find('0',colpos) num=float(line[zpos:50]) sum1=0+num
Are you sure that last line is right? Its effectively just doing sum1 = num adding zero does nothing interesting. So sum1 ends up at whatever num was at the end of the loop. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor