Untitled
unknown
plain_text
2 years ago
5.2 kB
4
Indexable
class Shape: ID = 0 pass class Rectangle(Shape): # наследуется от Shape # 1) определите конструктор # 2) переопределите метод __str__ def __init__(self): Shape.ID += 1 self.ID = Shape.ID def __str__(self): return f"{self.ID}:Rectangle" class Ellipse(Shape): # наследуется от Shape # 1) определите конструктор # 2) переопределите метод __str__ def __init__(self): Shape.ID += 1 self.ID = Shape.ID def __str__(self): return f"{self.ID}:Ellipse" class Square(Shape): # наследуется от Shape # 1) определите конструктор # 2) переопределите метод __str__ def __init__(self): Shape.ID += 1 self.ID = Shape.ID def __str__(self): return f"{self.ID}:Square" class Shape: def area(self): pass class Rectangle(Shape): # наследуется от Shape a = 5 # первая сторона b = 10 # вторая сторона def __init__(self, a, b): self.a = a self.b = b def area(self): return self.a * self.b def __str__(self): return f"{self.area()}, Rectangle" pass class Ellipse(Shape): # наследуется от Shape radius = 5 # первый радиус second_radius = 10 # второй радиус def __init__(self, radius, second_radius): self.r = radius self.sr = second_radius def area(self): return int(self.r * self.sr * 3.14) def __str__(self): return f"{self.area()}, Ellipse" pass class Square(Shape): # наследуется от Shape a = 5 # сторона квадрата def __init__(self, a): self.a = a def area(self): return self.a ** 2 def __str__(self): return f"{self.area()}, Square" pass class ShapeList(list): # наследуется от list def append(self, obj): if issubclass(type(obj), Shape): self.insert(-1, obj) def __str__(self): return '\n'.join([str(obj) for obj in sorted(self, key=lambda x: x.area())]) class Shape: def area(self): pass def __eq__(self, other): return self.area() == other.area() def __ne__(self, other): return self.area() != other.area() def __lt__(self, other): return self.area() < other.area() def __le__(self, other): return self.area() <= other.area() def __gt__(self, other): return self.area() > other.area() def __ge__(self, other): return self.area() >= other.area() class Rectangle(Shape): # наследуется от Shape a = 5 # первая сторона b = 10 # вторая сторона def __init__(self, a, b): self.a = a self.b = b def area(self): return self.a * self.b class Ellipse(Shape): # наследуется от Shape radius = 5 # первый радиус second_radius = 10 # второй радиус def __init__(self, radius, second_radius): self.r = radius self.sr = second_radius def area(self): return int(self.r * self.sr * 3.14) class Square(Shape): # наследуется от Shape a = 5 # сторона квадрата def __init__(self, a): self.a = a def area(self): return self.a ** 2 class Window: def __init__(self, height=100, width=200, square=20000): self.__height = height self.__width = width self.__square = square def getSquare(self): return self.__square def getHeight(self): return self.__height def getWidth(self): return self.__width def updateSquare(self): self.__square = self.__height * self.__width def setHeight(self, new_height): self.__height = new_height self.updateSquare() def setWidth(self, new_width): self.__width = new_width self.updateSquare() pass class IntList(list): def append(self, obj): if isinstance(obj, int): super().append(obj) def positive_sum(self): return sum([i for i in self if i > 0]) def negative_sum(self): return sum([i for i in self if i < 0]) def insert(self, index, obj): if isinstance(obj, int): super().insert(index, obj) def extend(self, lst): for obj in lst: if isinstance(obj, int): super().append(obj) class MyStr(str): def join(self, iterable): new_iterable = [] for item in iterable: if isinstance(item, (int, float)): new_iterable.append(str(item)) elif isinstance(item, list): new_iterable.append(MyStr(self).join(item)) elif isinstance(item, str): new_iterable.append(item) return super().join(new_iterable)
Editor is loading...