OK so i dont get how to make this professor class call on this lecturer class
So i have this code i'm trying to work through first is this
class Lecturer (Person):
def lecture (self, stuff):
self.say(stuff + "- you should be taking notes")
then i'm trying to make a class called professor which calls on this lecture def i made code like this
class Professor (Person):
def profess (self, stuff):
self.say("Its intuitively obvious that")
However here comes the problem i need to bring the lecture def in so that the def profess is calling on it meanin开发者_开发问答g that it adds the first part of the profess to the ending.
ex. X profess "Its intuitively obvious that.....whatever wants to be said - you should be taking notes"
i just dont get how to make it call on it, do you need to put like Lecturer.say (self, stuff) or something of the sort, its apart of my hw to learn python on our own but any help would be appreciated while i continue to work on it myself.
Then Professor should either 'be a' Lecturer or 'have a' Lecturer.
class Person(object):
def say(self, stuff):
return stuff
class Lecturer(Person):
def lecture(self, stuff):
return self.say(str(stuff) + " - you should be taking notes")
class Professor1(Lecturer): # 'is a' Lecturer
def profess(self, stuff):
return self.lecture("Its intuitively obvious that "+str(stuff))
class Professor2(Person): # 'has a' lecturer
def __init__(self):
super(Professor2,self).__init__()
self.lecturer = Lecturer()
def profess(self, stuff):
return self.lecturer.lecture("Its intuitively obvious that "+str(stuff))
p1 = Professor1()
print(p1.profess('Earth is flat'))
p2 = Professor2()
print(p2.profess('Earth is flat'))
results in
Its intuitively obvious that Earth is flat - you should be taking notes
Its intuitively obvious that Earth is flat - you should be taking notes
It seems like what you want is to create a subclass.
class Lecturer(Person):
def lecture(self, stuff):
self.say(stuff + "- you should be taking notes")
class Professor(Lecturer):
pass
Since this is homework, I'll leave you to figure out what to replace pass
with.
精彩评论