I am learning python and have question . After running this code ,the result displayed is
"Name is Bob and salary is50000 and work is main.PizzaRobot object at 0x00000000028EECC0>>"
I want "work" to be displayed for each object in str rather than calling obj.work() for each object .
In this problem output should be "Name is Bob and salary is50000 and work is Bob makes pizza"
Thanks
class Employee():
def __init__(self,name,salary = 0):
self.name = name
self.salary = salary
def giveraise(self,percent):
self.salary = self.salary + self.salary * percent
def __str__(self):
return "Name is {0} and salary is{1} and work is {2}".format(self.name,self.salary,self.work)
def work(self):
print(self.name ,"does stuff")
class chef(Employee):
def __init__(self,name):
Employee.__init__(self,name,50000)
def work(self):
print(self.name ,"makes food")
class PizzaRobot(chef):
def __init__(self,name):
chef.__init__(self,name)
def work(self):
print(self.name ,"makes pizza")
if __name__ == "__main__":
bob = PizzaRobot("Bob")
print(bob)
super().__init__(name,50000)and give each class an occupation attribute