-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path102-square.py
More file actions
53 lines (44 loc) · 1.38 KB
/
Copy path102-square.py
File metadata and controls
53 lines (44 loc) · 1.38 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
#!/usr/bin/python3
class Square:
""" A class that defines a square by its size
"""
def __eq__(self, other):
return self.__size == other.__size
def __lt__(self, other):
return self.__size < other.__size
def __le__(self, other):
return self.__size <= other.__size
def __ne__(self, other):
return self.__size != other.__size
def __gt__(self, other):
return self.__size > other.__size
def __ge__(self, other):
return self.__size >= other.__size
def __init__(self, size=0):
""" Method to initialize the square object
"""
if not isinstance(size, int):
raise TypeError("size must be an integer")
elif size < 0:
raise ValueError("size must be >= 0")
else:
self.__size = size
def area(self):
""" Method that returns the square are of the object
"""
return (self.__size ** 2)
@property
def size(self):
""" Method to returns the size value
"""
return self.__size
@size.setter
def size(self, value):
""" Method to set the size value of the square object
"""
if not isinstance(value, int):
raise TypeError("size must be an integer")
elif value < 0:
raise ValueError("size must be >= 0")
else:
self.__size = value