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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started