-
Notifications
You must be signed in to change notification settings - Fork 0
/
figure.py
72 lines (53 loc) · 1.1 KB
/
figure.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
import math
class Fig:
def __init__(self, x, y):
self.x = x
self.y = y
def get_coord(self):
return self.x, self.y
class Circle(Fig):
"""
>>> c = Circle(5, 6, 10)
>>> c.square()
314.1592653589793
>>> c.perim()
62.83185307179586
"""
def __init__(self, x, y, r):
super().__init__(x, y)
self.r = r
def square(self):
return math.pi * self.r ** 2
def perim(self):
return 2 * math.pi * self.r
class Rect(Fig):
"""
>>> r = Rect(1, 6, 60, 5)
>>> r.square()
300
>>> r.perim()
130
"""
def __init__(self, x, y, w, l):
super().__init__(x, y)
self.w = w
self.l = l
def square(self):
return self.w * self.l
def perim(self):
return 2 * (self.w + self.l)
class Square(Rect):
"""
>>> s = Square(4, 7, 10)
>>> s.square()
100
>>> s.perim()
40
>>> s.get_coord()
(4, 7)
"""
def __init__(self, x, y, w):
super().__init__(x, y, w, w)
if __name__ == '__main__':
import doctest
doctest.testmod()