-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject49.py
80 lines (36 loc) · 852 Bytes
/
project49.py
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
# Polymorphism
# Duck-Typing
class MyEditor:
def execute(self):
print("compiling")
print("running")
class PyCharm:
def execute(self):
print("compiling")
print("running")
class Laptop:
def code(self,ide):
ide.execute()
IDE1 = PyCharm()
IDE2 = MyEditor()
lap1 = Laptop()
lap1.code(IDE1)
print()
lap1.code(IDE2)
print()
class Duck:
def fly(self):
print("Duck flying")
class Sparrow:
def fly(self):
print("Sparrow flying")
class Whale:
def swim(self):
print("Whale swimming")
for animal in Duck(), Sparrow(), Whale():
try:
animal.fly()
print("It's a bird")
except:
animal.swim()
print("it's not a bird")