Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print max numbers in a list
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):

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)

Possibly Related Threads…
Thread Author Replies Views Last Post
  adding numbers in a list Nickd12 2 325 Jan-15-2021, 12:46 PM
Last Post: Serafim
  Print variable values from a list of variables xnightwingx 3 554 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  importing a list of numbers into python script barrypyth 8 984 Aug-22-2020, 09:10 PM
Last Post: barrypyth
  Print the number of items in a list on ubuntu terminal buttercup 2 644 Jul-24-2020, 01:46 PM
Last Post: ndc85430
  Is there a way i print odd and even numbers separately? spalisetty06 5 611 Jul-21-2020, 06:48 PM
Last Post: spalisetty06
  Summing a list of numbers Oldman45 6 705 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 5,097 Jul-01-2020, 03:53 PM
Last Post: ndc85430
  Topic: “Filter numbers with a list comprehension” (PyBite #107) Drone4four 4 680 Jun-11-2020, 08:31 PM
Last Post: Drone4four
  taking input doesnt print as list bntayfur 2 538 Jun-04-2020, 02:48 AM
Last Post: bntayfur
  Supposed to print out even numbers DallasPCMan 4 561 May-21-2020, 05:50 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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