2
question: Using the text file notes_students.dat write a program that calculates the minimum and maximum score of each student and prints the name of each student along with their maximum and minimum score. 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
my code:
arq=open('notas_estudantes.dat','r')
conteudo=arq.readlines()
arq.close()
for item in conteudo:
lista=item.split()
lista.sort()
print(lista[-1],':','Nota Maxima:',lista[-2],'Nota Minima:',lista[0])
when will I print this:
jose : Nota Maxima: 40 Nota Minima: 10
pedro : Nota Maxima: 23 Nota Minima: 16
suzana : Nota Maxima: 9 Nota Minima: 11
gisela : Nota Maxima: 45 Nota Minima: 10
joao : Nota Maxima: 89 Nota Minima: 14
the others are all correct however when it comes to the part of Uzana it does not give the correct result, I wonder if it is something error of Pyhton or it was myself that I missed something in the code.
My question is why the Sort ? For the stated purpose is not necessary the
sort
and of course it would be less efficient to sort the list.– Isac