-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path102-square.py
59 lines (45 loc) · 1.29 KB
/
102-square.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
#!/usr/bin/python3
""" class Square that defines a square"""
class Square:
""" class Square that defines a square"""
def __init__(self, size=0):
""" init square
Args:
value (int): size of the square.
"""
self.size = size
@property
def size(self):
"""int: private size.
Returns:
Private size.
"""
return self.__size
@size.setter
def size(self, value):
"""Sets value into size, must be int.
Args:
value (int): size of the square.
"""
if type(value) is not int and type(value) is not float:
raise TypeError('size must be a number')
elif value < 0:
raise ValueError('size must be >= 0')
else:
self.__size = value #: size of the square
def area(self):
"""returns the area
Returns:
area.
"""
return self.__size**2
def __lt__(self, other):
return self.size < other.size
def __le__(self, other):
return self.size <= other.size
def __eq__(self, other):
return self.size == other.size
def __ne__(self, other):
return self.size != other.size
def __ge__(self, other):
return self.size >= other.size