Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt, pi
- class Compare:
- _area: int
- _type: type
- def check_class(funk):
- def wrapper(self_obj, other_obj):
- if not isinstance(other_obj, self_obj._type):
- raise TypeError(f"Variable is not {self_obj._type.__name__}")
- return funk(self_obj, other_obj)
- return wrapper
- def __init__(self, area, type_) -> None:
- self.area = area
- self._type = type_
- @check_class
- def __eq__(self, other) -> bool:
- return self.get_space() == other.get_space()
- @check_class
- def __ne__(self, other) -> bool:
- return self.get_space() != other.get_space()
- @check_class
- def __lt__(self, other) -> bool:
- return self.get_space() < other.get_space()
- @check_class
- def __le__(self, other) -> bool:
- return self.get_space() <= other.get_space()
- @check_class
- def __gt__(self, other) -> bool:
- return self.get_space() > other.get_space()
- @check_class
- def __ge__(self, other) -> bool:
- return self.get_space() >= other.get_space()
- class Rectangle (Compare):
- length: int
- width: int
- def get_space(self) -> int:
- return self.length * self.width
- def __init__(self, a, b) -> None:
- self.length = a
- self.width = b
- super().__init__(self.get_space(), self.__class__)
- def __str__(self) -> str:
- return f'length: {self.length}, width: {self.width}'
- def get_length(self) -> int:
- return self.length
- def get_width(self) -> int:
- return self.width
- def get_perimeter(self) -> int:
- return 2 * (self.length + self.width)
- class Triangle (Compare):
- a: int
- b: int
- c: int
- def __init__(self, a, b, c) -> None:
- self.a = max(a, b, c)
- self.c = min(a, b, c)
- self.b = a + b + c - self.a - self.c
- super().__init__(self.get_space(), self.__class__)
- def __str__(self) -> str:
- return f'A: {self.a}, B: {self.b}, C: {self.c}'
- def get_sides(self) -> int:
- return (self.a, self.b, self.c)
- def get_perimeter(self) -> int:
- return sum(self.get_sides())
- def get_space(self) -> int:
- p = self.get_perimeter() / 2
- return sqrt(p * (p - self.a) * (p - self.b) * (p - self.c))
- class Circle (Compare):
- radius: int
- def __init__(self, r) -> None:
- self.radius = r
- super().__init__(self.get_space(), self.__class__)
- def __str__(self) -> str:
- return f'Radius: {self.radius}'
- def get_radius(self):
- return self.radius
- def get_perimeter(self) -> int:
- return 2 * self.radius * pi
- def get_space(self) -> int:
- return (self.radius ** 2) * pi
- class Square (Rectangle):
- def __init__(self, a) -> None:
- Rectangle.__init__(self, a, a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement