question: Using the text file notas_estudantes.dat write a program that calculates the average of the notes of each student and prints the name and average of each student. file:
jose 10 15 20 30 40
pedro 23 16 19 22
suzana 8 22 17 14 32 17 24 21 2 9 11 17
gisela 12 28 21 45 26 10
joao 14 32 25 16 89
I used the following code:
arq=open('notas_estudantes.dat','r')
conteudo=arq.readlines()
arq.close()
soma=0
for item in conteudo:
nom=item.split()
for x in nom[1:300]:
soma+=int(x)
print(nom[0],':',soma/(len(nom)-1))
The problem is that it adds the first line and divides it right but it adds more to the second and so on, I'm not sure how to add it to the line and divide it correctly. thus:
jose : 23
pedro : 48.75
suzana : 32.416666666666664
gisela : 88.5
joao : 141.4