4DM3M

15-16

Apr 21st, 2021
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.16 KB | None | 0 0
  1. from multipledispatch import dispatch
  2. from abc import abstractmethod
  3.  
  4.  
  5. class Table:
  6.     def __init__(self, l, w, h):
  7.         self.length = l
  8.         self.width = w
  9.         self.high = h
  10.         self._color = ""
  11.         self._material = ""
  12.  
  13.     @property
  14.     def color(self):
  15.         if self._color == "":
  16.             return "Цвет не задан"
  17.         return self._color
  18.  
  19.     @color.setter
  20.     def color(self, color):
  21.         self._color = color
  22.  
  23.     @property
  24.     def material(self):
  25.         if self._material == "":
  26.             return "Материал не задан"
  27.         return self._material
  28.  
  29.     @material.setter
  30.     def material(self, material):
  31.         self._material = material
  32.  
  33.     @abstractmethod
  34.     def get_square(self):
  35.         pass
  36.  
  37.     @dispatch()
  38.     def get_high(self):
  39.         return self.high
  40.  
  41.     @dispatch(int)
  42.     def get_high(self, shelf_height):
  43.         return self.high + shelf_height
  44.  
  45.     @abstractmethod
  46.     def add_shelf(self, shelf_high):
  47.         pass
  48.  
  49.     @abstractmethod
  50.     def get_shelfHeight(self):
  51.         pass
  52.  
  53.     @staticmethod
  54.     def about():
  55.         print('вероятнее всего, это что-то связанное со столами')
  56.  
  57.     @staticmethod
  58.     def kufar_find_bookTable():
  59.         print("Столов-книжек в радиусе 100 км не обнаружено")
  60.  
  61.     @abstractmethod
  62.     def info(self):
  63.         return 'Некоторый стол'
  64.  
  65.  
  66. class KitchenTable(Table):
  67.     @dispatch(int, int, int)
  68.     def __init__(self, l, w, h):
  69.         super().__init__(l, w, h)
  70.         self._places = 4
  71.  
  72.     @dispatch(int, int, int, int)
  73.     def __init__(self, l, w, h, pl=4):
  74.         super().__init__(l, w, h)
  75.         self._places = pl
  76.  
  77.     @property
  78.     def places(self):
  79.         return self._places
  80.  
  81.     @places.setter
  82.     @places.setter
  83.     def places(self, places):
  84.         self._places = places
  85.  
  86.     def info(self):
  87.         return 'Кухонный стол'
  88.  
  89.     def get_square(self):
  90.         return self.length * self.width
  91.  
  92.     # places = property(get_places, set_places)
  93.  
  94.  
  95. class DeskTable(Table):
  96.     def __init__(self, l, w, h):
  97.         super().__init__(l, w, h)
  98.         self._shelf = []
  99.  
  100.     def get_square(self):
  101.         return self.length * self.width
  102.  
  103.     def add_shelf(self, shelf_high):
  104.         self._shelf.append(shelf_high)
  105.  
  106.     def get_shelfHeight(self):
  107.         if len(self._shelf) == 0:
  108.             return "Полок не обнаружено"
  109.  
  110.         sum = 0
  111.         for element in self._shelf:
  112.             sum += element
  113.         return sum / len(self._shelf)
  114.  
  115.     def info(self):
  116.         return "Письменный стол"
  117.  
  118.  
  119. class ComputerTable(DeskTable):
  120.     def __init__(self, l, w, h, restSquare=0):
  121.         super().__init__(l, w, h)
  122.         self._restSquare = restSquare
  123.  
  124.     def get_square(self):
  125.         return super().get_square() - self._restSquare
  126.  
  127.     def info(self):
  128.         return 'Компьютерый стол'
  129.  
  130.  
  131. lst = []
  132.  
  133. quant = int(input('Введите количество столов: '))
  134. for iter in range(quant):
  135.     Type = int(input('Какой стол вы хотите создать? \n 1 - Кухонный\n 2 - Письменный\n 3 - Компьютерный\n'))
  136.     if Type == 1:
  137.         print('Введите Длину, ширину, высоту, кол-во мест (по умолчанию 4):')
  138.         args = input()
  139.         argslst = []
  140.         temp = None
  141.         for arg in args.split():
  142.             argslst.append(int(arg))
  143.         if len(argslst) == 3:
  144.             temp = KitchenTable(argslst[0], argslst[1], argslst[2])
  145.             lst.append(temp)
  146.         elif len(argslst) == 4:
  147.             temp = KitchenTable(argslst[0], argslst[1], argslst[2], argslst[3])
  148.             lst.append(temp)
  149.         else:
  150.             print('Неверные входные данные!\n')
  151.  
  152.     elif Type == 2:
  153.         print('Введите Длину, ширину, высоту:')
  154.         args = input()
  155.         argslst = []
  156.         temp = None
  157.         for arg in args.split():
  158.             argslst.append(int(arg))
  159.         if len(argslst) == 3:
  160.             temp = DeskTable(argslst[0], argslst[1], argslst[2])
  161.             lst.append(temp)
  162.         else:
  163.             print('Неверные входные данные!')
  164.     elif Type == 3:
  165.         print('Введите Длину, ширину, высоту, площадь, занимаемая компьютером:')
  166.         args = input()
  167.         argslst = []
  168.         temp = None
  169.         for arg in args.split():
  170.             argslst.append(int(arg))
  171.         if len(argslst) == 3:
  172.             temp = ComputerTable(argslst[0], argslst[1], argslst[2])
  173.             lst.append(temp)
  174.         elif len(argslst) == 4:
  175.             temp = ComputerTable(argslst[0], argslst[1], argslst[2], argslst[3])
  176.             lst.append(temp)
  177.         else:
  178.             print('Неверные входные данные!')
  179.  
  180.     if len(lst) != 0:
  181.         for element in lst:
  182.             print(element.info())
  183.             element.color = "blue"
  184.             print(element.color)
  185.             print(element.get_square())
  186.  
Advertisement
Add Comment
Please, Sign In to add comment