|
| 1 | +class Point: |
| 2 | + def __init__(self, x, y): |
| 3 | + self.x = x |
| 4 | + self.y = y |
| 5 | + |
| 6 | + def __eq__(self, other): |
| 7 | + if not isinstance(other, type(self)): |
| 8 | + raise TypeError(f"'other' must be of type '{type(self).__name__}'") |
| 9 | + return self.x == other.x and self.y == other.y |
| 10 | + |
| 11 | + def __lt__(self, other): |
| 12 | + if not isinstance(other, type(self)): |
| 13 | + raise TypeError(f"'other' must be of type '{type(self).__name__}'") |
| 14 | + return self.x < other.x and self.y < other.y |
| 15 | + |
| 16 | + def __gt__(self, other): |
| 17 | + if not isinstance(other, type(self)): |
| 18 | + raise TypeError(f"'other' must be of type '{type(self).__name__}'") |
| 19 | + return self.x > other.x and self.y > other.y |
| 20 | + |
| 21 | + def __le__(self, other): |
| 22 | + if not isinstance(other, type(self)): |
| 23 | + raise TypeError(f"'other' must be of type '{type(self).__name__}'") |
| 24 | + return self.x <= other.x and self.y <= other.y |
| 25 | + |
| 26 | + def __ge__(self, other): |
| 27 | + if not isinstance(other, type(self)): |
| 28 | + raise TypeError(f"'other' must be of type '{type(self).__name__}'") |
| 29 | + return self.x >= other.x and self.y >= other.y |
| 30 | + |
| 31 | + def __ne__(self, other): |
| 32 | + if not isinstance(other, type(self)): |
| 33 | + raise TypeError(f"'other' must be of type '{type(self).__name__}'") |
| 34 | + return self.x != other.x and self.y != other.y |
0 commit comments