1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Salsk061 [2.6K]
3 years ago
15

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

ethod (__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.
Computers and Technology
1 answer:
shusha [124]3 years ago
5 0

Answer:

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 __eq__(self,student):

return self.name == student.name

 

def __ge__(self,student):

return self.name == student.name or self.name>student.name

 

def __lt__(self,student):

return self.name<student.name

 

def __str__(self):

return "Name: " + self.name + "\nScores: " + \

" ".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)

 

print("\nSecond student")

student2 = Student("Ken", 5)

print(student2)

 

print("\nThird student")

student3 = Student("Amit", 5)

print(student3)

 

print("\nChecking equal student1 and student 2")

print(student.__eq__(student2))

 

print("\nChecking equal student1 and student 3")

print(student.__eq__(student3))

 

print("\nChecking greater than equal student1 and student 3")

print(student.__ge__(student3))

 

print("\nChecking less than student1 and student 3")

print(student.__lt__(student3))

if __name__ == "__main__":

You might be interested in
A hockey stick hits a puck on the ice. identify an action-reaction pair in this situation.
Alika [10]
The stick exerts a force on the puck; the puck exerts a force on the stick.
7 0
4 years ago
Which functions return a logical value (TRUE or FALSE)?
Ludmilka [50]

Answer:

Functions with a boolean return type.

Explanation:

If the return type is boolean, the only possible values are true or false.

8 0
3 years ago
The output of a logic gate is 1 when all its inputs are at logic 0. the gate is either
alexira [117]

Answer: NOR or XNOR gate

Explanation:

In NOR gate we get a high value of the output only when its input has a low value. i.e. for 0 and 0 we get a value of 1.

In XNOR gate which is the compliment of the OR gate we get the output as 1 when all the inputs are 0.

5 0
3 years ago
A specailized output device for producing charts, maps, and very high-quality drawings is a? ​
Irina18 [472]

Answer:

a plotter

Explanation:

8 0
3 years ago
The length of time the valve is open, expressed in degrees of crankshaft rotation, is called camshaft
CaHeK987 [17]
It's A duration-a<span> rating system applied to the engine camshaft that determines how long the valve will be open relative to crankshaft movement in degrees</span>
4 0
3 years ago
Other questions:
  • Which of these is an on-site metric for social media marketing?
    13·1 answer
  • you want to discard your old computer ,want to securely erase that data from your hard drive. what can you use to do this and wh
    12·1 answer
  • You are in charge of designing a menu tree for navigating 1,250 books in a digital library. Present an argument of whether the m
    12·1 answer
  • The ____ tool allows a user to connect to the active registry database and make changes that are effective immediately. editreg.
    12·1 answer
  • Use the variables k and total to write a while loop that computes the sum of the squares of the first 50 counting numbers, and a
    10·1 answer
  • 1. Which of the following is NOT an example of systems software? (Points : 1)
    5·2 answers
  • Give the imporntance of having standard funiture in the laboratory​
    11·1 answer
  • To drive defensively means taking proactive measures to avoid accident situations regardless of their potential causes.
    6·2 answers
  • What are the three fundamental principals of mnemonics??
    6·2 answers
  • Suppose a company A decides to set up a cloud to deliver Software as a Service to its clients through a remote location. Answer
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!