Skip to content

Instantly share code, notes, and snippets.

@romunov
Created November 7, 2022 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romunov/7ec3700e4e333f6cc9d7421967dbfc92 to your computer and use it in GitHub Desktop.
Save romunov/7ec3700e4e333f6cc9d7421967dbfc92 to your computer and use it in GitHub Desktop.
""" The task is to write comments (after ## ??) on every instance and describe it with the phrase is-a and has-a.
For further reference, please see ex41. """
## Animal is-a object (yes, sort of cinfusing) look at the extra credit
class Animal(object):
pass
## ?? Class Dog is-a Animal that has-a __init__that takes self and name as parameters
class Dog(Animal):
def __init__(self, name):
## ?? from self get the name attribute and set it to name
self.name = name
## ?? Class Cat is-a Animal that as-a __init__ that takes self and name as parameters
class Cat(Animal):
def __init__(self, name):
## ?? from self get the name attribute and set it to name
self.name = name
## ?? Class Person is-a object that has-a __init__ that takes self and name as parameters
class Person(object):
def __init__(self, name):
## ?? from self get the name attribute and set it to name
self.name = name
## Person has-a pet of some kind
self.pet = None
## ?? Class Employee is-a Person that has-a __init__ that takes elf, name and salary as parameters
class Employee(Person):
def __init__(self, name, salary):
## ?? from Person get the __init__ function and call it with self and name parameters
super(Employee, self).__init__(name)
## ?? from self get the salary attribute and set it to salary
self.salary = salary
## ?? Class Fish is-a object
class Fish(object):
pass
## ?? Class Salmon is-a Fish
class Salmon(Fish):
pass
## ?? Class Halibut is-a Fish
class Halibut(Fish):
pass
## rover is-a Dog
rover = Dog("Rover")
## ?? set satan to an instance of class Cat with the parameter 'Satan'
satan = Cat('Satan')
## ?? set mary to an instance of class Person with the parameter 'Mary'
mary = Person("Mary")
## ?? from mary get the attribute pet and set it to satan
mary.pet = satan
## ?? set frank to an instance of class Employee with parameters 'Frank' and Salary 120000
frank = Employee("Frank", 120000)
## ?? from frank get the attribute pet and set it to rover
frank.pet = rover
## ?? set flipper to an instance of class Fish
flipper = Fish()
## ?? set rouse to an instance of class Salmon
crouse = Salmon()
## ?? set harry to an instance of class Halibut
harry = Halibut()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment