##### Print max numbers in a list
 Print max numbers in a list jimmoriarty Unladen Swallow Posts: 1 Threads: 1 Joined: Sep 2020 Reputation: Sep-25-2020, 07:04 AM 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): maxStudents.append(student[grade.index(i)]) print(maxStudents)``` Reply DPaul Minister of Silly Walks Posts: 343 Threads: 39 Joined: Dec 2017 Reputation: Sep-25-2020, 07:29 AM 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) Paul Reply

 Possibly Related Threads… Thread Author Replies Views Last Post adding numbers in a list Nickd12 2 258 Jan-15-2021, 12:46 PM Last Post: Serafim Print variable values from a list of variables xnightwingx 3 496 Sep-01-2020, 02:56 PM Last Post: deanhystad importing a list of numbers into python script barrypyth 8 853 Aug-22-2020, 09:10 PM Last Post: barrypyth Print the number of items in a list on ubuntu terminal buttercup 2 589 Jul-24-2020, 01:46 PM Last Post: ndc85430 Is there a way i print odd and even numbers separately? spalisetty06 5 551 Jul-21-2020, 06:48 PM Last Post: spalisetty06 Summing a list of numbers Oldman45 6 627 Jul-12-2020, 05:30 PM Last Post: Oldman45 How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 6 4,700 Jul-01-2020, 03:53 PM Last Post: ndc85430 Topic: “Filter numbers with a list comprehension” (PyBite #107) Drone4four 4 620 Jun-11-2020, 08:31 PM Last Post: Drone4four taking input doesnt print as list bntayfur 2 485 Jun-04-2020, 02:48 AM Last Post: bntayfur Supposed to print out even numbers DallasPCMan 4 529 May-21-2020, 05:50 PM Last Post: ndc85430

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020