Python Forum
Print max numbers in a list - Printable Version

+- Python Forum (
+-- Forum: Python Coding (
+--- Forum: General Coding Help (
+--- Thread: Print max numbers in a list (/Thread-Print-max-numbers-in-a-list)

Print max numbers in a list - jimmoriarty - Sep-25-2020

So, guys, i'm having a problem with my code. What i need to do is take grades of n students and put on a list, and take their grades e put on otherlist what i did, but, i'm not getting print the names of the students if more than one get the highest grade. My code until now:
student = []
grade = []
maxStudents =[]

while len(student) < 5:
    student.append(input('Write de student name'))
    grade.append(int(input('Write the student grade')))

for i in grade:
    if i == max(grade,key=int):


RE: Print max numbers in a list - DPaul - Sep-25-2020

There are many solutions, knowing that ".index(i)" will give you the first occurence only.
Two suggestions:
1) Start an independent counter incremented in each loop. student[x], will give the different names (2 extra lines)
2) Do a diffenrent kind of loop , like "for i in range(len(grade)):", again student[i] will do the trick. (no extra lines)