-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram43.py
More file actions
55 lines (42 loc) · 1.09 KB
/
program43.py
File metadata and controls
55 lines (42 loc) · 1.09 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
#Abstraction-------
from abc import ABC,abstractmethod
class Shape(ABC):
def __init__(self,dim1,dim2):
self.dim1 = dim1
self.dim2 = dim2
@abstractmethod
def area(self):
pass
class Triangle(Shape):
def area(self):
area = 0.5 * self.dim1 * self.dim2
print("Triangle of area : ",area)
class Rectangle(Shape):
def area(self):
area = self.dim1 * self.dim2
print("Rectangle of area : ",area)
t1 = Triangle(10,20)
t1.area()
r1 = Rectangle(10,20)
r1.area()
#Abstraction-------
from abc import ABC,abstractmethod
class Shape(ABC):
def __init__(self,dim1,dim2):
self.dim1 = dim1
self.dim2 = dim2
@abstractmethod
def area(self):
pass
class Triangle(Shape):
def area(self):
area = 0.5 * self.dim1 * self.dim2
print("Triangle of area : ",area)
class Rectangle(Shape):
def area(self):
area = self.dim1 * self.dim2
print("Rectangle of area : ",area)
t1 = Triangle(10,20)
t1.area()
r1 = Rectangle(10,20)
r1.area()