-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path102-square.py
executable file
·54 lines (42 loc) · 1.59 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
#!/usr/bin/python3
"""Define a class Square."""
class Square:
"""A class that defines a square"""
def __init__(self, size=0):
"""Initialize a new square.
Args:
size (int): The size of the new square.
"""
self.__size = size
@property
def size(self):
"""property(get&set) for the current size of the square."""
return self.__size
@size.setter
def size(self, value):
if (not isinstance(value, int) and not isinstance(value, float)):
raise TypeError('size must be a number')
if (size < 0):
raise ValueError('size must be >= 0')
self.__size = value
def area(self):
"""Returns the area of the current square."""
return (self.__size**2)
def __eq__(self, other_square):
"""Returns the == comparision to a Square."""
return self.area() == other_square.area()
def __ne__(self, other_square):
"""Returns the != comparison to a Square."""
return self.area() != other_square.area()
def __lt__(self, other_square):
"""Returns the < comparison to a Square."""
return self.area() < other_square.area()
def __le__(self, other_square):
"""Returns the <= comparison to a Square."""
return self.area() <= other_square.area()
def __gt__(self, other_square):
"""Returns the > comparison to a Square."""
return self.area() > other_square.area()
def __ge__(self, other_square):
"""Returns the >= compmarison to a Square."""
return self.area() >= other_square.area()