Hello i have a school exercise that i cant solve, im almost there but something is missing me, so i have 2 .txt files one with student names and other one with students grades they are like:
nomesAlunos.txt :
Ricardo
Filipa
Teresa
Claúdio
nomesNotas.txt :
14 15 14 17
14 14
13 10
13 10 11
i should create a new file where i have the student name followed by student average grades, my code is like:
final=open('data/notasFinal.txt','w')
nomes=open('data/nomesAlunos.txt')
notas=open('data/nomesNotas.txt')
for linha in nomes:
final.write(linha)
for line in notas:
lista=line.split()
media=(sum((int(numeros) for numeros in lista)))/(len(lista))
final.write(str(media))
nomes.close()
notas.close()
my final .txt file is like this right now:
Ricardo
15.014.011.511.333333333333334Filipa
Teresa
Claúdio
SOLVED:
final=open('data/notasFinal.txt','w')
nomes=open('data/nomesAlunos.txt')
notas=open('data/nomesNotas.txt')
media=[]
i=0
for linhas in notas:
lista=linhas.split()
media.append((sum((int(numeros) for numeros in lista)))/(len(lista)))
for nome in nomes:
alunos=nome.split()
final.write(f"{alunos[0]:30}{media[i]}\n")
i+=1
nomes.close()
notas.close()
final.close()