-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathshapes.py
More file actions
57 lines (39 loc) · 1.08 KB
/
shapes.py
File metadata and controls
57 lines (39 loc) · 1.08 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
import math
class IShape:
""" Interface for Shape classes, defines the perimeter and area methods
"""
def perimeter(self):
""" returns the perimeter of the shape
"""
return None
def area(self):
""" returns the area of the shape
"""
return None
class Disk(IShape):
""" Disk Shape class
"""
def __init__(self, radius):
self.radius = radius
return
def perimeter(self):
return 2.*math.pi*self.radius
def area(self):
return math.pi*self.radius*self.radius
class Rectangle(IShape):
""" Rectangle Shape class
"""
def __init__(self, width, height):
self.width = width
self.height = height
return
def perimeter(self):
return 2.*(self.width+self.height)
def area(self):
return self.width*self.height
class Square(Rectangle):
""" Square Shape class
"""
def __init__(self, size):
Rectangle.__init__(self, size, size)
return