-
Notifications
You must be signed in to change notification settings - Fork 5
/
102-square.py
executable file
·121 lines (108 loc) · 3.63 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python3
"""Module containing the Square class"""
class Square:
"""The Square class"""
def __init__(self, size=0):
"""Initializing an instance of Square
Args:
size (int): The size of the Square instance. Default value is 0.
"""
self.size = size
@property
def size(self):
"""int: size of the Square instance"""
return self.__size
@size.setter
def size(self, size):
if not isinstance(size, int):
raise TypeError("size must be an integer")
if size < 0:
raise ValueError("size must be >= 0")
self.__size = size
def area(self):
"""Returns the current square area of the instance
Returns:
int: The square of size
"""
return self.__size ** 2
def __eq__(self, other):
"""Check if the area of the instance is the same as the area of 'other'.
Returns:
bool: The return Value. True if self.area == other.area. False
otherwise, or 'other' is not of type Square.
"""
if isinstance(other, Square):
if self.area() == other.area():
return True
else:
return False
else:
return False
def __ne__(self, other):
"""Check if the area of the instance is not the same as the area of
'other'.
Returns:
bool: The return Value. True if self.area != other.area. False
otherwise, or 'other' is not of type Square.
"""
if isinstance(other, Square):
if self.area() != other.area():
return True
else:
return False
else:
return False
def __gt__(self, other):
"""Check if the area of the instance is greater than the area of 'other'.
Returns:
bool: The return Value. True if self.area > other.area. False
otherwise, or 'other' is not of type Square.
"""
if isinstance(other, Square):
if self.area() > other.area():
return True
else:
return False
else:
return False
def __ge__(self, other):
"""Check if the area of the instance is greater than or equal to the
area of 'other'.
Returns:
bool: The return Value. True if self.area >= other.area. False
otherwise, or 'other' is not of type Square.
"""
if isinstance(other, Square):
if self.area() >= other.area():
return True
else:
return False
else:
return False
def __lt__(self, other):
"""Check if the area of the instance is less than the area of 'other'.
Returns:
bool: The return Value. True if self.area < other.area. False
otherwise, or 'other' is not of type Square.
"""
if isinstance(other, Square):
if self.area() < other.area():
return True
else:
return False
else:
return False
def __le__(self, other):
"""Check if the area of the instance is less than or equal to the area
of 'other'.
Returns:
bool: The return Value. True if self.area <= other.area. False
otherwise, or 'other' is not of type Square.
"""
if isinstance(other, Square):
if self.area() <= other.area():
return True
else:
return False
else:
return False