-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path102-square.py
executable file
·69 lines (46 loc) · 1.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
#!/usr/bin/python3
"""
9. Compare 2 squares
A class Square that defines a square
"""
class Square:
"""Class that defines a square"""
def __init__(self, size=0):
"""Define private instance attribute: size"""
self.__size = size
@property
def size(self):
""""Function that returns private instance attribute: size"""
return self.__size
@size.setter
def size(self, value):
"""
Define private instance attribute: value
Raise TypeError & ValueError if not int or <0 resp.
"""
if not isinstance(value, int):
raise TypeError('size must be an integer')
if value < 0:
raise ValueError('size must be >= 0')
self.__size = value
def area(self):
"""Function that calculates area"""
return self.__size ** 2
def __le__(self, other):
"""Function that compares if a sqare is <= another"""
return self.area() <= other.area()
def __lt__(self, other):
"""Function that compares if a square is < another"""
return self.area() < other.area()
def __ge__(self, other):
"""Function that compares if a square is >= another"""
return self.area() >= other.area()
def __ne__(self, other):
"""Function that compares if a square is != another"""
return self.area() != other.area()
def __gt__(self, other):
"""Function that compares if a square is > another"""
return self.area() > other.area()
def __eq__(self, other):
"""Function that compares f a square == another"""
return self.area() == other.area()