Respected Expert coders, Hello! I am absolutely new in the world of coding. I have started to learn python.I am using ZED Shah's LPTHW. For the first time I am stuck in the class section. I am attaching my code for rectification, please help me. The code is not giving any out put, simply back to prompt.
Animal is-a object
class Animal(object):
pass
class Dog(Animal):
def __init__(self, name):
self.name = name
class Cat(Animal):
def __init__(self, name):
self.name = name
class Person(object):
def __init__(self, name):
self.name = name
self.pet = None
class Employee(Person):
def __init__(self, name, salary):
## ?? hmm what is this strange magic?
super(Employee, self).__init__(name)
## ??
self.salary = salary
class Fish(object):
pass
class Salmon(Fish):
pass
class Halibut(Fish):
pass
rover = Dog("Rover")
satan = Cat("Satan")
mary = Person("Mary")
mary.pet = satan
frank = Employee("Frank", 120000)
frank.pet = rover
flipper = Fish()
crouse = Salmon()
harry = Halibut()
答案 0 :(得分:0)
我刚刚完成了这个练习,所有Zed想要的是让你熟悉“is-a”和“has-a”的短语。区分类,对象和变量。代码本身没有其他目的,只是为了您的利益而进行的练习。