-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram41.py
More file actions
90 lines (68 loc) · 1.92 KB
/
program41.py
File metadata and controls
90 lines (68 loc) · 1.92 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
#A practical example of inheritance-------
class shape:
def __init__(self,dim1,dim2):
self.dim1 = dim1
self.dim2 = dim2
def area(self):
print("I am area method of shape class : ")
class Triangle(shape):
def area(self):
area = 0.5 * self.dim1 * self.dim2
print("I am area method of Triangle class : ",area)
class Rectangle(shape):
def area(self):
area = self.dim1 * self.dim2
print("I am area method of Rectangle class : ",area)
class Addiction(shape):
def area(self):
area = self.dim1 * self.dim2
print("Addiction : ",area)
t1 = Triangle(10,20)
t1.area()
t2 = Rectangle(10,20)
t2.area()
t3 = Addiction(100,200)
t3.area()
#A practical example of inheritance-------
class shape:
def __init__(self,dim1,dim2):
self.dim1 = dim1
self.dim2 = dim2
def area(self):
print("It is a Shape class : ")
class Triangle(shape):
def area(self):
area = 0.5 * self.dim1 * self.dim2
print("Area of Triangle : ",area)
class Rectangle(shape):
def area(self):
area = self.dim1 * self.dim2
print("Area of Rectangle : ",area)
class Addiction(shape):
def area(self):
area = self.dim1 + self.dim2
print("Addiction : ",area)
class Subtrauction(shape):
def area(self):
area = self.dim1 - self.dim2
print("Subtruction : ",area)
class Multification(shape):
def area(self):
area = self.dim1 * self.dim2
print("Multification : ",area)
class Division(shape):
def area(self):
area = self.dim1 / self.dim2
print("Division : ",area)
t1 = Triangle(10,20)
t1.area()
r1 = Rectangle(10,20)
r1.area()
add1 = Addiction(100,200)
add1.area()
sub = Subtrauction(200,100)
sub.area()
mul = Multification(10,10)
mul.area()
div = Division(200,10)
div.area()