Suppose there is a class Roster. Roster has one variable, roster, which is a List of tuples containing the names of students and their number grades--for example, [('Richard', 90), ('Bella', 67), ('Christine', 85), ('Francine', 97)]. Roster has a function findValedictorian that returns the name of the student with the highest grade. Find the valedictorian of the Roster object englishClass and store it in the variable valedictorian.

Respuesta :

Answer:

class Roster:

   def __init__(self,student):

       self.student = student

   def findValedictoian(self):

       

       highscore = 0

       studentList=[]

       bStudent = []

       valedictorian =''

       for pupil in self.student:

           if pupil[1] > highscore:

               highscore = pupil[1]

              valedictorian = pupil[0]

       return valedictorian

   

student = [('rich', 90), ('Bella', 67),('philip', 56)]

englishClass= Roster(student)

print(englishClass.findValedictoian())

Explanation:

we define the roster class using the class keyword, within the class we have our __init__ constructor and we initialize the variable student.

A class method findValedictoian is defined and it compares the grades of each student and returns the name of the student with the highest grade.

An instance is created for English class and the findValedictorian method is called and the valedictorian is printed to the screen.

ACCESS MORE