forked from imtiazahmad007/PythonCourse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassignment_01.py
123 lines (69 loc) · 1.68 KB
/
assignment_01.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Assignment 1:
"""
Define a class hierarchy representing animals with a parent class Animal
and child classes such as dog, fish and bird. Each subclass animal should have
a name and an age and should have 2 methods defined in it: move(), eat().
The move method needs to be specific for a given animal where as the
eat() method should be generic for all animals. The methods don't need to
do anything except print information about who is doing what.
After creating the class hierarchy, create instances of each of the 3 animals
dog, fish and bird and make them eat and move.
"""
# Your Code Below:
# Solution:
# class Animal:
# def __init__(self):
# print("Animal Constructed")
#
# def move(self):
# print("Animal Moving...")
#
# def eat(self):
# print("Animal Eating...")
#
#
#
# class Bird(Animal):
#
# def __init__(self, bird_age, bird_name):
# Animal.__init__(self)
# self.age = bird_age
# self.name = bird_name
#
# def move(self):
# print("Bird flying...")
#
#
#
# class Fish(Animal):
#
# def __init__(self, bird_age, bird_name):
# Animal.__init__(self)
# self.age = bird_age
# self.name = bird_name
#
# def move(self):
# print("Fish Swimming...")
#
#
# class Dog(Animal):
#
# def __init__(self, bird_age, bird_name):
# Animal.__init__(self)
# self.age = bird_age
# self.name = bird_name
#
# def move(self):
# print("Dog Running ...")
#
# mydog = Dog(3, "wolfy")
# mydog.move()
# mydog.eat()
#
# mydog = Fish(1, "nemo")
# mydog.move()
# mydog.eat()
#
# mydog = Bird(3, "jojo")
# mydog.move()
# mydog.eat()