-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstraction.py
59 lines (41 loc) · 948 Bytes
/
abstraction.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
"""Abstraction in python
"""
from abc import ABC, abstractmethod
class Shape(ABC):
"""Shape Class
"""
@abstractmethod
def area(self):
"""area of shape
"""
@abstractmethod
def perimeter(self):
"""perimeter of shape
"""
class Square(Shape):
"""Square Class(Shape subclass)
"""
def __init__(self, side):
self.side = side
def area(self):
return self.side ** 2
def perimeter(self):
return self.side * 4
class Circle(Shape):
"""Circle Class(Shape Subclass)
"""
PI = 3.14
def __init__(self, radius):
self.radius = radius
def area(self):
return self.PI * self.radius ** 2
def perimeter(self):
return 2 * self.PI * self.radius
# square object
square = Square(5)
print(square.area())
print(square.perimeter())
# circle object
circle = Circle(2)
print(circle.area())
print(circle.perimeter())