-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path01-properties.py
More file actions
70 lines (52 loc) · 1.51 KB
/
01-properties.py
File metadata and controls
70 lines (52 loc) · 1.51 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
from math import pi
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
@property
def x(self):
return self._x
@x.setter
def x(self, value):
assert isinstance(value, int), 'Booooo! Expecting an int'
self._x = value
@property
def y(self):
return self._y
@y.setter
def y(self, value):
assert isinstance(value, int), 'Booooo! Expecting an int'
self._y = value
def move_by(self, dx, dy):
self.x += dx
self.y += dy
def __str__(self):
return f'A Point at {self.x}, {self.y}'
def __repr__(self):
return f'{self.__class__.__name__}({self.x}, {self.y})'
class Circle:
def __init__(self, center, radius):
self.center = center
self.radius = radius
@property
def center(self):
return self._center
@center.setter
def center(self, value):
assert isinstance(value, Point), 'Booooo! Expecting a Point'
self._center = value
@property
def radius(self):
return self._radius
@radius.setter
def radius(self, value):
assert isinstance(value, int), 'Booooo! Expecting an int'
self._radius = value
@property
def area(self):
return pi * self.radius ** 2
def __str__(self):
return f'A Circle at {self.center.x}, {self.center.y} and ' + \
f'radius {self.radius}'
def __repr__(self):
return f'{self.__class__.__name__}({self.center!r}, {self.radius!r})'