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
dalvyx [7]
3 years ago
13

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

uld test for less than. The third method 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.
Current code is below:
"""
File: student.py
Resources to manage a student's name and test scores.
"""
class Student(object):
"""Represents a student."""
def __init__(self, name, number):
"""All scores are initially 0."""
self.name = name
self.scores = []
for count in range(number):
self.scores.append(0)
def getName(self):
"""Returns the student's name."""
return self.name

def setScore(self, i, score):
"""Resets the ith score, counting from 1."""
self.scores[i - 1] = score
def getScore(self, i):
"""Returns the ith score, counting from 1."""
return self.scores[i - 1]

def getAverage(self):
"""Returns the average score."""
return sum(self.scores) / len(self._scores)

def getHighScore(self):
"""Returns the highest score."""
return max(self.scores)

def __str__(self):
"""Returns the string representation of the student."""
return "Name: " + self.name + "\nScores: " + \
" ".join(map(str, self.scores))

# Write method definitions here
def main():
"""A simple test."""
student = Student("Ken", 5)
print(student)
for i in range(1, 6):
student.setScore(i, 100)
print(student)
if __name__ == "__main__":
main()

Computers and Technology
1 answer:
Alja [10]3 years ago
4 0

Answer:

Check the explanation

Explanation:

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__":

main()

Kindly check the below images to see the code screenshot and code output :

You might be interested in
On a timeline, a milestone 11 years in the future will be to the
aniked [119]

Answer:

D. Left,left

11 is less than 20 as well as it is less than 25 years. And we move from left to right on the timeline. Thus 11 is left of 20 and it is left of 25 years as well. And timeline is the core of a project management software. The Gantt and Pert chart are totally based on the timeline. Software like Microsoft project use the timeline quite a lot, and you cannot survive without the knowledge  of the timeline in software project management.

Explanation:

Timeline knowledge is a must for a software professional, and the above answer does not require explanation.

6 0
4 years ago
Describe the necessary Java commands to create a Java program for creating a lottery program using arrays and methods.
netineya [11]
I think each lottery ticket will cost £5 each so you would count in 5s till you reach the amount of tickets to get the answer which is £25
5 0
2 years ago
Read 2 more answers
Match the actions of individuals with the code of conduct they are adhering to. Sofia is an HR Manager who keeps all employee re
aksik [14]

All the code of conducts is good and it is expected from each and every employee of the organization. Employee details needs to be kept confidential and Sofia, the HR manager is adhering to it. Employee’s productivity increases if unnecessary use of mobile phone stops.

It is always recommended to use free items than the copyrighted items. It’s a good ethical practice. Becky is also right, because he considers work as work and does not get deviated with dinner invites and gifts.

5 0
3 years ago
Read 2 more answers
What specific type of hardware card inserts into a web server that contains one or more co-processors to handle ssl/tls processi
o-na [289]
A <span>specific type of hardware card which is inserted into a web server that contains one or more co-processors to handle ssl/tls processing is 
</span>SSL/TLS Accelerator.
8 0
4 years ago
Rewrite following program using for loop no=3456 while no&gt;0 : print(no%10) no=no/10
PtichkaEL [24]

Answer:

no=3456  

for x in reversed(str(no)):

 print(x)

Explanation:

If you turn the number into a string and then reverse it, you can achieve the same output.

8 0
3 years ago
Read 2 more answers
Other questions:
  • The __________ is the continuity of control of evidence that makes it possible to account for all that has happened to evidence
    14·2 answers
  • The picture that graphically represents the items you use in Windows is called a/an
    12·2 answers
  • What hernia repair codes can be reported with add-on code 49568?
    6·1 answer
  • Why might your coworker suggest encrypting an archive file before e-mailing it??
    8·1 answer
  • 1.which of the following CANNOT be copyrighted?
    7·1 answer
  • 7.1 What is the basic building block of an 802.11 WLAN? 7.2 Define an extended service set. 7.3 List and briefly define IEEE 802
    5·1 answer
  • What is the function of a slide transition in a presentation program? A. It enables you to change the presentation layouts. B. I
    15·1 answer
  • Who designed analatic engine in the 1930's?​
    10·1 answer
  • Windows workstations all have elements of server software built-in. What are these elements, and why is the Windows Professional
    9·1 answer
  • QUICK HELP ME PLEASE
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!