-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex42_3.py
More file actions
96 lines (69 loc) · 1.91 KB
/
Copy pathex42_3.py
File metadata and controls
96 lines (69 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""Exercise 42.3, Learning Python the Hard Way"""
class Animal(object):
"""Animal is-a object (yes, sort of confusing) look @ the extra credit."""
print "Altogether Animals!"
print "=" * 19
class Dog(Animal):
"""Dog is-a Animal"""
def __init__(self, name):
# ??
self.name = name
print "%s says: Woof!" % self.name
class Cat(Animal):
"""Cat is-a Animal"""
def __init__(self, name):
# ??
self.name = name
print "%s says: Meow!" % self.name
class Person(object):
"""Person is-a object"""
def __init__(self, name):
# ??
self.name = name
print "%s says: Hello!" % self.name
# Person has-a pet of some kind
self.pet = None
print "My name is %s and this is my pet, %s." % (self.name, self.pet)
class Employee(Person):
"""Employee is-a Person"""
def __init__(self, name, salary):
# ?? hmm what is this strange magic?
super(Employee, self).__init__(name)
# ??
self.salary = salary
class Fish(object):
"""Fish is-a object"""
def __init__(self, name):
# ??
self.name = name
print "I'm %s the fish!" % self.name
class Salmon(Fish):
"""Salmon is-a fish"""
def __init__(self, name):
# ??
self.name = name
print "I'm %s the salmon!" % self.name
class Halibut(Fish):
"""Halibut is-a fish"""
def __init__(self, name):
# ??
self.name = name
print "I'm %s the halibut!" % self.name
# rover is-a Dog
ROVER = Dog("Rover")
# Satan is-a Cat
SATAN = Cat("Satan")
# mary is-a Person
MARY = Person("Mary")
# mary's pet is-a satan
MARY.pet = SATAN
# frank is-a Employee
FRANK = Employee("Frank", 120000)
# frank's pet is-a rover
FRANK.pet = ROVER
# flipper is-a fish
FLIPPER = Fish("Flipper")
# crouse is-a Salmon
CROUSE = Salmon("Crouse")
# harry is-a Halibut
HARRY = Halibut("Harry")