My Programming Lab PYTHON help please There is a class calle

My Programming Lab (PYTHON) help please...

There is a class called Roster whose constructor takes a List of tuples with the names of students and their grades in the class, for example -- [(\'Richard\', 98), (\'Benny\', 55), (\'Katie\', 87), (\'Sally\', 76)].
Create an instance of the Roster class, including the following students and their respective grades, and store it in the variable  mathClass: Jacob, 65 Frankie, 86 Lina, 94 Arnold, 63 Amanda, 87

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

class Roster:
   roster = []

   def __init__(self, rostr): #constructor using rostr
       self.roster = rostr
      
      
   def getRoster(self): #getter method for roster
       return self.roster
      
mathClass = Roster([(\'Richard\', 98), (\'Benny\', 55), (\'Katie\', 87), (\'Sally\', 76)])   #create a mathClass Roster class object

print(\"mathClass.roster : \",mathClass.getRoster())   #print mathClass.roster

-------------------------------------------------------------------

OUTPUT:

My Programming Lab (PYTHON) help please... There is a class called Roster whose constructor takes a List of tuples with the names of students and their grades i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site