diff --git a/youngjin.han/learning-node02-2020.org b/youngjin.han/learning-node02-2020.org index d2215f4..3c26201 100644 --- a/youngjin.han/learning-node02-2020.org +++ b/youngjin.han/learning-node02-2020.org @@ -1,3 +1,12 @@ +* 2020-06-12 +*** Python #9: +**** DONE Lecture content + CLOSED: [2020-06-12 금 22:43] + - Same structure as "Python #2" + - Exercise 42 + - Review all previous exercises, ensure you understand them +**** Lecture material + - Available on https://cloud.ungleich.ch/s/435FyfrQyEq6oF3 * 2020-06-10 *** Python #8: **** DONE Lecture content diff --git a/youngjin.han/python-the-hard-way/ex42.py b/youngjin.han/python-the-hard-way/ex42.py new file mode 100644 index 0000000..f6341cc --- /dev/null +++ b/youngjin.han/python-the-hard-way/ex42.py @@ -0,0 +1,94 @@ +## Animal is parents +## Animal is-a object (yes, sort of confusing) look at the extra credit +class Animal(object): + pass + +## Animal is parents and Dog is child +## Dog is-a Animal and has-a __init__ that takes self and name parameters +class Dog(Animal): + + def __init__(self, name): + ## Dos has-a name + self.name = name + +## Animal is parents and Cat is child +## Cat is-a Animal and has-a __init__ that takes self and name parameters +class Cat(Animal): + + def __init__(self, name): + ## Cat has-a name + self.name = name + +## Person is parents +## Person is-a object and has-a __init__ that takes self and name parameters +class Person(object): + + def __init__(self, name): + ## Person has-a name + self.name = name + + ## Person has-a pet of some kind + self.pet = None + +## Persion is parents and Employee is child +## Employee is-a Person and has-a __init__ that takes self and name parameters +class Employee(Person): + + def __init__(self, name, salary): + ## ?? hmm what is this strange magic? + ## From super, get the __init__ function, and call it with parameters self, name + super(Employee, self).__init__(name) + ## Employee has-a salary + self.salary = salary + +## Fish is parents +## Fish is-a object +class Fish(object): + pass + +## Fish is parents and Salmon is child +## Salmon is-a Fish +class Salmon(Fish): + pass + +## Fish is parents and Halibut is child +## Halibut is-a Fish +class Halibut(Fish): + pass + + +## Set rover to an instance of class Dog +## rover is-a Dog that has-a name is-a Rover +rover = Dog("Rover") + +## Set satan to an instance of class Cat +## stan is-a cat that has-a name is-a Satan +satan = Cat("Satan") + +## Set mary to an instance of class Person +## mary is-a Person that has-a name is-a Mary +mary = Person("Mary") + +## From mary, get the pet attribute, and set it to satan +## mary's pet is-a cat that has-a name that is-a Satan +mary.pet = satan + +## Set frank to an instance of class Employee +## frank is-a Employee and salary is-a 120000 +frank = Employee("Frank", 120000) + +## From frank, get the pet attribute, and set it to rover +## frank's pet is-a dog that has-a name that is-a Rover +frank.pet = rover + +## Set flipper to an instance of class Fish +## flipper is-a Fish +flipper = Fish() + +## Set crouse to an instance of class Salmon +## crouse is-a Salmon +crouse = Salmon() + +## Set harry to an instance of class Halibut +## harry is-a Halibut +harry = Halibut() diff --git a/youngjin.han/python.org b/youngjin.han/python.org index cdfb9d9..2b24ffb 100644 --- a/youngjin.han/python.org +++ b/youngjin.han/python.org @@ -1,8 +1,11 @@ +* 2020-06-12 + - ex42.py + - MRO(method resolution order) * 2020-06-10 ** note - ex40.py - none - - ex40.py + - ex41.py - none * 2020-06-08 ** note