Access over 20 million homework & study documents
search

Consider the following hierarchy of classes class Person (object) d

Content type

User Generated

Rating

Showing Page:
1/4
Consider the following hierarchy of classes: class Person
(object): def_init_(self, name): self.name - name def
say(self, stuff): return self.name + says: def_str_(self):
return self.name + stuff class Lecturer(Person): def
lecture(self, stuff): return \'I believe that \' +
Person.say(self, stuff) class Professor(Lecturer): def
say(self, stuff): return self.name + \' says:\' +
self.lecture(stuff) class ArrogantProfessor(Professor) def
say(self, stuff): return \'It is obvious that\' + self.say(stuff)
As written, this code leads to an infinite loop when using
the class. Change the definition of so that the following
behavior is achieved: e = Person(\'eric\') lessthanorequalto
= Lecturer(\"eric\") pe = Professor(\'eric\') ae =
ArrogantProfessor(\"eric\") >>> e.say (\'the sky is blue\')
eric says: the sky is blue >>> le.say (\'the sky is blue\')
eric says: the sky is blue >>> le. lecture (\'the sky is blue\')
I believe that eric says: the sky is blue >>> pe.say (\'the
sky is blue\') eric says: I believe that eric says: the sky is
blue >>> pe. lecture (\'the sky is blue\') I believe that eric
says: the sky is blue >>> ae. say (\'the sky is blue\') eric
says: It is obvious that eric says: the sky is blue >>> ae.
lecture (\'the sky is blue\') It is obvious that eric says: the
sky is blue Paste ONLY your class in the box below. Do
not leave any debugging print statements. For this
question, you will not be able to see the test cases we run.
This problem will test your ability to come up with your own
test cases.
Solution

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/4
class Person(object):
def __init__(self, name):
self.name = name
def say(self, stuff):
return self.name + \' says: \' + stuff
def __str__(self):
return self.name
class Lecturer(Person):
def lecture(self, stuff):
return \'I believe that \' + Person.say(self, stuff)
class Professor(Lecturer):
def say(self, stuff):
return self.name + \' says: \' + self.lecture(stuff)
class ArrogantProfessor(Person):
def say(self, stuff):
return super(ArrogantProfessor,
self).say(self.lecture(stuff))
def lecture(self, stuff):
return \'It is obvious that \' + super(ArrogantProfessor,
self).say(stuff)
e = Person(\'eric\')
le = Lecturer(\'eric\')
pe = Professor(\'eric\')

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/4

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 4 pages?
Access Now

Unformatted Attachment Preview

Consider the following hierarchy of classes: class Person (object): def_init_(self, name): self.name - name def say(self, stuff): return self.name + says: def_str_(self): return self.name + stuff class Lecturer(Person): def lecture(self, stuff): return \'I believe that \' + Person.say(self, stuff) class Professor(Lecturer): def say(self, stuff): return self.name + \' says:\' + self.lecture(stuff) class ArrogantProfessor(Professor) def say(self, stuff): return \'It is obvious that\' + self.say(stuff) As written, this code leads to an infinite loop when using the class. Change the definition of so that the following behavior is achieved: e = Person( \'eric\') lessthanorequalto = Lecturer(\"eric\") pe = Professor(\'eric\') ae = ArrogantProfessor(\"eric\") >>> e.say (\'the sky is blue\') eric says: the sky is blue >>> le.say ( \'the sky is blue\') eric says: the sky is blue >>> le. lecture ( \'the sky is blue\') I believe that eric says: the sky is blue >>> pe.say ( \'the sky is blue\') eric says: I believe that e ric says: the sky is blue >>> pe. lecture (\'the sky is blue\') I believe that eric says: the sky is blue >>> ae. say ( \'the sky is blue\') eric says: It is obvious that eri ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
I use Studypool every time I need help studying, and it never disappoints.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4