Question: Python3 Add three methods to the Student class that compare twoStudent objects. One method (__eq__) should test for equality. A second method (__lt__) should test

Python3

Add three methods to the Student class that compare twoStudent objects. One method (__eq__) should test for equality. A second method (__lt__) should test for less than. The third method (__ge__) should test for greater than or equal to. In each case, the method returns the result of the comparison of the two students names. Include a main function that tests all of the comparison operators.

original code:

class Student(object):

def __init__(self, name, number): self.name = name self.scores = [] for count in range(number): self.scores.append(0)

def getName(self): return self.name def setScore(self, i, score): self.scores[i - 1] = score

def getScore(self, i): return self.scores[i - 1] def getAverage(self): return sum(self.scores) / len(self._scores) def getHighScore(self): return max(self.scores) def __str__(self): return "Name: " + self.name + " Scores: " + \ " ".join(map(str, self.scores))

def main(): student = Student("Ken", 5) print(student) for i in range(1, 6): student.setScore(i, 100) print(student)

if __name__ == "__main__": main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!