4
question: Using the text file notes_students.dat write a program that averages each student’s grades and prints each student’s name and average. filing cabinet:
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 he sums up the notes of the first line and divides right but he sums up the second and so on, I’m not sure how to make him add up line by line and divide correctly. being like this:
jose : 23
pedro : 48.75
suzana : 32.416666666666664
gisela : 88.5
joao : 141.4
our easy... xD Thank you very much
– Matheus Andrade