im currently making a program that takes in the names and scores of the student but i dont know how to get the top 3 scores when the scores starts to get the same
ex student 1 is 100 student 2 is 99 student 3 and 4 is 98 i dont know how to print both student 3 and 4 at the same time.

def getStudent():
names = []
h1 =[]
h2 =[]
h3 =[]
fob = open('Student.txt')
names.append(name)
fob.close()
print(name)

while True:
fob = open("Student.txt",'r')
name = raw_input("Student Name: ")
if name == "1":
break
opw = open("Student.txt",'w')
opw.writelines(raw)
opw.write(name +" ")
opw.write('\n')
opw.close()
else:
print("Grade must be 50 - 100 ")
else:
print("Grade must be 50 - 100 ")
getStudent()


Do you mean like this?

a = [5,4,4]
i = 0
while(i<len(a)):
if (i + 1) <= len(a):
if a[i] == (a[i+1]):
print "Equal grades %s and %s" % (a[i], (a[i+1]))
i = i + 2
else:
i = i + 1
else:
print …

Well, it is kind of the same concept but what you could do is actually save your data in a dictionary {StudentName : Grade} then used sorted to sort it by values in a reversed order so the first element will be the highest.
Then when outputting them make a …

## All 8 Replies

Do you mean like this?

a = [5,4,4]
i = 0
while(i<len(a)):
if (i + 1) <= len(a):
if a[i] == (a[i+1]):
print "Equal grades %s and %s" % (a[i], (a[i+1]))
i = i + 2
else:
i = i + 1
else:
print "Last item in the list %s" % (a[i])
i = i + 1


Output:

um no more like something like this
enter student name: A
enter student name: B
enter student name: C
enter student name: D
enter student name: E
enter student name: F

A : 100
B : 99
D : 99
C : 97
E : 97

Well, it is kind of the same concept but what you could do is actually save your data in a dictionary {StudentName : Grade} then used sorted to sort it by values in a reversed order so the first element will be the highest.
Then when outputting them make a function get the best 3 grades, where you loop through the values of the dictionary, and save {student : grade} in a new dictionary that you will return before exiting the function. Your looping condition will be that there are 3 different values in the new dictionary that will be returned

can you please give and example of that loop im really bad at that

Well, I'll give you a quick example using list of numbers and a structure called "set", that does not contain the same object multiple times so if it has 3 elements inside, that means 3 different grades have been processed

grades = [5,4,4,5,5,5,3,1,2,3,5,7,1]
aSet = set()
if len(aSet) >= 3 and grade not in aSet:
break


Output is:

Student's grade is 7


this is my new code please help me sort the values on student by highest to lowest as well as print the top 3 recurrint items

student = {}
top3 = {}
class getstudent():
def get(self):
fob = open("Students.txt",'r')
name = raw_input("Student Name: ")
if (name == '-1' or grade == -1):
print 'lol'
self.sort();
opw = open("Students.txt",'w')
opw.writelines(raw)
opw.write(name +" ")
opw.write('\n')
opw.close()
self.get();
else:
print("Grade must be 50 - 100 ")
self.get();
def sort(self):
print 'No Student Record'
else:

print student

g = getstudent();
g.get();


here's my new code when ever i sort things out the 100 always go last why is that please help me sort and them and preview the top 3 recurring students.

grades = []
names = []
student = {}
top3 = {}
class getstudent():
def get(self):
fob = open("Students.txt",'r')
name = raw_input("Student Name: ")
if (name == '-1' or grade == '-1'):
self.sort();
opw = open("Students.txt",'w')
opw.writelines(raw)
opw.write(name +" ")
opw.write("\n")
opw.close()
self.get();
else:
print("Grade must be 50 - 100 ")
self.get();

def sort(self):
print 'No Student Record'
else:
names.append(name1)