Mar-27-2021, 10:24 AM
(This post was last modified: Mar-27-2021, 10:26 AM by snippsat.
Edit Reason: Added code tag
)
I start to learn programming few weeks ago and I'm trying to do an exercise that ask me to calculate the average of a list of number from a text file. This is my code:
file=input('Enter a file name: ')
open=open(file)
count=0
for line in open:
line=line.rstrip()
if line.startswith('X-DSPAM-Confidence:'):
count=count+1
search=line.find(':')
numbers=line[search+1:]
float(numbers)
Media=sum(numbers)/count
print('Media spam confidence: ', Media)It gives me back this error:Error:Traceback (most recent call last):
File "C:\Users\frank\OneDrive\Documenti\Atom\Esercizi\Esercizio_file.py", line 11, in <module>
Media=sum(numbers)/count
TypeError: unsupported operand type(s) for +: 'int' and 'str'I understand the error but I don't know how to fix it
