Advertisement
J3st3rs_j0k3

inf_lb3_final

Dec 21st, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.08 KB | None | 0 0
  1. class HouseScheme():
  2.     def __init__(self, liverooms, livespace, wc):
  3.         if livespace >= 0 and type(wc) == bool:
  4.             self.liverooms = liverooms
  5.             self.livespace = livespace
  6.             self.wc = wc
  7.         else:
  8.             raise ValueError('Invalid value')
  9.  
  10. class CountryHouse(HouseScheme): # Класс должен наследоваться от HouseScheme
  11.     def __init__(self, liverooms, livespace, wc, floors, yard):
  12.         super().__init__(liverooms, livespace, wc)
  13.         self.floors = floors
  14.         self.yard = yard
  15.  
  16.  
  17.     def __str__(self):
  18.         return f'Country House: Количество жилых комнат {self.liverooms}, Жилая площадь {self.livespace}, Совмещенный санузел {self.wc}, Количество этажей {self.floors}, Площадь участка {self.yard}.'  
  19.  
  20.  
  21.     def __eq__(self, other):
  22.         if (self.livespace == other.livespace) and (self.yard == other.yard) and ((self.floors - 1) <= (other.floors) <= (self.floors + 1)):
  23.             return True
  24.         else:
  25.             return False
  26.  
  27.  
  28.  
  29.  
  30.  
  31. class Apartment(HouseScheme): # Класс должен наследоваться от HouseScheme
  32.     def __init__(self, liverooms, livespace, wc, floors, direction):
  33.         super().__init__(liverooms, livespace, wc)
  34.         if floors >= 1 and floors <= 15 and (direction == 'N' or direction == 'S' or direction == 'W' or direction == 'E'):
  35.             self.floors = floors
  36.             self.direction = direction
  37.         else:
  38.             raise ValueError('Invalid value')
  39.  
  40.     def __str__(self):
  41.         return f'Apartment: Количество жилых комнат {self.liverooms}, Жилая площадь {self.livespace}, Совмещенный санузел {self.wc}, Этаж {self.floors}, Окна выходят на {self.direction}.'
  42.  
  43. class CountryHouseList(list): # список деревенских домов -- "деревня", наследуется от класса list
  44.     def __init__(self, name):
  45.         super().__init__()
  46.         self.name = name
  47.  
  48.     def append(self, p_object):
  49.         if issubclass(type(p_object), CountryHouse):
  50.             super().append(p_object)
  51.         else:
  52.             raise TypeError("Invalid type "+ str(type(p_object)))
  53.  
  54.     def total_square(self):
  55.         total_square = 0
  56.         for i in self:
  57.             total_square += i.livespace     #Посчитать общую жилую площадь
  58.         return total_square
  59.  
  60.  
  61. class ApartmentList(list):  # список городских квартир -- ЖК, наследуется от класса list
  62.     def __init__(self, name):
  63.         super().__init__()
  64.         self.name = name
  65.  
  66.  
  67.     def extend(self, iterable):
  68.         super().extend(list(filter(lambda x: type(x) == Apartment, iterable)))    
  69.  
  70.     def floor_view(self, floors, directions):
  71.         for direct_floor in list(filter(lambda x: floors[0] <= x.floors <= floors[1]  and x.direction in directions, self)):
  72.             print('{}: {}'.format(direct_floor.direction, direct_floor.floors))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement