Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Question Protected by Community Bot
deleted 1 character in body
Source Link
gsamaras
  • 73.7k
  • 50
  • 210
  • 330
make code blocks concerning the task part of the quote
Source Link
das-g
  • 10.1k
  • 6
  • 44
  • 95

Consider the following hierarchy of classes:

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(Professor): 
 def say(self, stuff): 
 return 'It is obvious that ' + self.say(stuff)
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(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 Arrogant Professor class.

Change the definition of ArrogantProfessor so that the following behavior is achieved:

e = Person('eric') 
le = Lecturer('eric') 
pe = Professor('eric') 
ae = ArrogantProfessor('eric')
e.say('the sky is blue') #returns eric says: the sky is blue
le.say('the sky is blue') #returns eric says: the sky is blue
le.lecture('the sky is blue') #returns believe that eric says: the sky is blue
pe.say('the sky is blue') #returns eric says: I believe that eric says: the sky is blue
pe.lecture('the sky is blue') #returns believe that eric says: the sky is blue
ae.say('the sky is blue') #returns eric says: It is obvious that eric says: the sky is blue
ae.lecture('the sky is blue') #returns It is obvious that eric says: the sky is blue
e = Person('eric') 
le = Lecturer('eric') 
pe = Professor('eric') 
ae = ArrogantProfessor('eric')
e.say('the sky is blue') #returns eric says: the sky is blue
le.say('the sky is blue') #returns eric says: the sky is blue
le.lecture('the sky is blue') #returns believe that eric says: the sky is blue
pe.say('the sky is blue') #returns eric says: I believe that eric says: the sky is blue
pe.lecture('the sky is blue') #returns believe that eric says: the sky is blue
ae.say('the sky is blue') #returns eric says: It is obvious that eric says: the sky is blue
ae.lecture('the sky is blue') #returns It is obvious that eric says: the sky is blue

myMy solution to this is:

But the checker gives only half marks for this solution.What What is the mistake that I am making and what are the test cases on which this code fails? (I am new to python and learned about classes some time ago.)

Consider the following hierarchy of classes:

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(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 Arrogant Professor class.

Change the definition of ArrogantProfessor so that the following behavior is achieved:

e = Person('eric') 
le = Lecturer('eric') 
pe = Professor('eric') 
ae = ArrogantProfessor('eric')
e.say('the sky is blue') #returns eric says: the sky is blue
le.say('the sky is blue') #returns eric says: the sky is blue
le.lecture('the sky is blue') #returns believe that eric says: the sky is blue
pe.say('the sky is blue') #returns eric says: I believe that eric says: the sky is blue
pe.lecture('the sky is blue') #returns believe that eric says: the sky is blue
ae.say('the sky is blue') #returns eric says: It is obvious that eric says: the sky is blue
ae.lecture('the sky is blue') #returns It is obvious that eric says: the sky is blue

my solution to this is:

But the checker gives only half marks for this solution.What is the mistake that I am making and what are the test cases on which this code fails? (I am new to python and learned about classes some time ago)

Consider the following hierarchy of classes:

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(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 Arrogant Professor class.

Change the definition of ArrogantProfessor so that the following behavior is achieved:

e = Person('eric') 
le = Lecturer('eric') 
pe = Professor('eric') 
ae = ArrogantProfessor('eric')
e.say('the sky is blue') #returns eric says: the sky is blue
le.say('the sky is blue') #returns eric says: the sky is blue
le.lecture('the sky is blue') #returns believe that eric says: the sky is blue
pe.say('the sky is blue') #returns eric says: I believe that eric says: the sky is blue
pe.lecture('the sky is blue') #returns believe that eric says: the sky is blue
ae.say('the sky is blue') #returns eric says: It is obvious that eric says: the sky is blue
ae.lecture('the sky is blue') #returns It is obvious that eric says: the sky is blue

My solution to this is:

But the checker gives only half marks for this solution. What is the mistake that I am making and what are the test cases on which this code fails? (I am new to python and learned about classes some time ago.)

deleted 24 characters in body
Source Link
L3viathan
  • 27.5k
  • 2
  • 63
  • 84
e = Person('eric') 
le = Lecturer('eric') 
pe = Professor('eric') 
ae = ArrogantProfessor('eric')
e.say(‘the'the sky is blue’blue') #returns eric says: the sky is blue
le.say(‘the'the sky is blue’blue') #returns eric says: the sky is blue
le.lecture(‘the'the sky is blue’blue') #returns believe that eric says: the sky is blue
pe.say(‘the'the sky is blue’blue') #returns eric says: I believe that eric says: the sky is blue
pe.lecture(‘the'the sky is blue’blue') #returns believe that eric says: the sky is blue
ae.say(‘the'the sky is blue’blue') #returns eric says: It is obvious that eric says: the sky is blue
ae.lecture(‘the'the sky is blue’blue') #returns It is obvious that eric says: the sky is blue
e = Person('eric') 
le = Lecturer('eric') 
pe = Professor('eric') 
ae = ArrogantProfessor('eric')
e.say(‘the sky is blue’) #returns eric says: the sky is blue
le.say(‘the sky is blue’) #returns eric says: the sky is blue
le.lecture(‘the sky is blue’) #returns believe that eric says: the sky is blue
pe.say(‘the sky is blue’) #returns eric says: I believe that eric says: the sky is blue
pe.lecture(‘the sky is blue’) #returns believe that eric says: the sky is blue
ae.say(‘the sky is blue’) #returns eric says: It is obvious that eric says: the sky is blue
ae.lecture(‘the sky is blue’) #returns It is obvious that eric says: the sky is blue
e = Person('eric') 
le = Lecturer('eric') 
pe = Professor('eric') 
ae = ArrogantProfessor('eric')
e.say('the sky is blue') #returns eric says: the sky is blue
le.say('the sky is blue') #returns eric says: the sky is blue
le.lecture('the sky is blue') #returns believe that eric says: the sky is blue
pe.say('the sky is blue') #returns eric says: I believe that eric says: the sky is blue
pe.lecture('the sky is blue') #returns believe that eric says: the sky is blue
ae.say('the sky is blue') #returns eric says: It is obvious that eric says: the sky is blue
ae.lecture('the sky is blue') #returns It is obvious that eric says: the sky is blue
deleted 1 character in body
Source Link
sid597
  • 1k
  • 4
  • 17
  • 33
Loading
Source Link
sid597
  • 1k
  • 4
  • 17
  • 33
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /