-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex42.py
More file actions
100 lines (76 loc) · 2.02 KB
/
ex42.py
File metadata and controls
100 lines (76 loc) · 2.02 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
97
98
99
100
# Animal is-a object (yes, sort of confusing) look at the extra credit
class Animal(object):
i = 10
j = 20
k = i+j
print "%d" %(k)
# Dog is-a animal
class Dog(Animal):
i = 10
j = 20
print (i+j)*1000
def __init__(self, name):
# Dog has-a name
self.name=name
# Cat is-a animal
class Cat(Animal):
def __init__(self,name):
# Cat has-a name
self.name=name
# Person is-a object
class Person(object):
Person = ['Ankit', 'Akshay', 'Vinod', 'Viral', 'Ashok', 'Amit']
print Person
def __init__(self,name):
# Person has-a name
self.name=name
# Person has-a pet of some kind
self.pet=None
# Employee is-a person
class Employee(Person):
def __init__(self, name, salary):
# hmm what is this strage magic ?
super(Employee, self).__init__(name)
# Employee has-a salary
self.salary=salary
# Fish is-a object
class Fish(object):
Fish = {
'PSA' : 'Opel',
'Tata Motors' : 'Jaguar',
'GM' : 'Corvette',
'BMW': 'Mini',
'Mercedes':'Smart',
'Renault':'Zoe',
'Toyota':'Lexus'
}
print Fish['PSA']
Fish['VW'] = 'Audi'
print Fish ['VW']
for OEM, brand in Fish.items():
print "\n%s owns %s brand\n" %(OEM, brand)
# Salmon is-a Fish
class Salmon(Fish):
pass
# Halibut is-a Fish
class Halibut(Fish):
pass
# instance of Dog that is-a "Rover"
rover = Dog("Rover")
# instance of Cat that is-a "Satan"
satan = Cat("Satan")
# instance of Person that is-a "Mary"
mary = Person("Mary")
# Take pet attribute of mary and set it to satan
mary.pet = satan
# franck is an instance of Employee that takes "Franck" & 120000 as parameters
franck = Employee("Franck", 120000)
print franck
# from franck take pet attribute and set it to rover
franck.pet=rover
# flipper is an instance of class Fish
flipper = Fish()
# crouse is an instance of class Salmon
crouse=Salmon()
# harry is an instance of class Halibut
harry = Halibut()