-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path102-square.py
More file actions
executable file
·53 lines (41 loc) · 1.28 KB
/
102-square.py
File metadata and controls
executable file
·53 lines (41 loc) · 1.28 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
"""Coordinates of a square"""
class Square:
"""Private instance attribute: size
Instantiation with area and position method """
def __init__(self, size=0):
"""Initializes attribute size """
self.size = size
def area(self):
"""Calculate area of square"""
return (self.__size * self.__size)
@property
def size(self):
"""Getter for square"""
return self.__size
@size.setter
def size(self, value):
"""Initializes attribute size """
if (type(value) is not int):
raise TypeError("size must be an integer")
if value < 0:
raise ValueError("size must be >= 0")
self.__size = value
def __eq__(self, other):
"""Equal"""
return self.size == other.size
def __ne__(self, other):
"""Not Equal"""
return self.size != other.size
def __lt__(self, other):
"""Less than"""
return self.size < other.size
def __le__(self, other):
"""Less than or equal"""
return self.size <= other.size
def __gt__(self, other):
"""Greater than"""
return self.size > other.size
def __ge__(self, other):
"""Greater than or equal"""
return self.size >= other.size