Advertisement
LilChicha174

Untitled

Dec 19th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. def check1(rooms, life_square, is_wc):
  2. rms = isinstance(rooms, int) and rooms >= 0
  3. lsq = (isinstance(life_square, int) or isinstance(life_square, float)) and life_square >= 0
  4. wc = isinstance(is_wc, bool)
  5. return rms and lsq and wc
  6.  
  7.  
  8. def check2(floors, area_square):
  9. flr = isinstance(floors, int) and floors > 0
  10. ars = (isinstance(area_square, int) or isinstance(area_square, float)) and area_square >= 0
  11. return flr and ars
  12.  
  13.  
  14. def check3(floor, window):
  15. fl = isinstance(floor, int) and 1 <= floor <= 15
  16. wd = isinstance(window, str) and window in 'NSEW'
  17. return fl and wd
  18.  
  19.  
  20. def Valuer():
  21. raise ValueError("Invalid value")
  22.  
  23.  
  24. class HouseScheme:
  25. def __init__(self, rooms, life_square, is_wc):
  26. ch1 = check1(rooms, life_square, is_wc)
  27. if ch1:
  28. self.rooms = rooms
  29. self.life_square = life_square
  30. self.wc = is_wc
  31. else:
  32. Valuer()
  33.  
  34.  
  35. class CountryHouse(HouseScheme):
  36. def __init__(self, rooms, life_square, is_wc, floors, area_square):
  37. ch2 = check2(floors, area_square)
  38. if ch2:
  39. super().__init__(rooms, life_square, is_wc)
  40. self.floors = floors
  41. self.area_square = area_square
  42. else:
  43. Valuer()
  44.  
  45. def __str__(self):
  46. return f"Country House: Количество жилых комнат {self.rooms}, Жилая площадь" \
  47. f" {self.life_square}, Совмещенный санузел {self.wc}, Количество этажей " \
  48. f"{self.floors}, Площадь участка {self.area_square}."
  49.  
  50. def __eq__(self, other):
  51. return self.life_square == other.life_square and self.area_square == other.area_square and \
  52. abs(self.floors - other.floors) <= 1
  53.  
  54.  
  55. class Apartment(HouseScheme):
  56. def __init__(self, rooms, life_square, is_wc, floor, window):
  57. ch3 = check3(floor, window)
  58. if ch3:
  59. super().__init__(rooms, life_square, is_wc)
  60. self.floor = floor
  61. self.window = window
  62. else:
  63. Valuer()
  64.  
  65. def __str__(self):
  66. return f'Apartment: Количество жилых комнат {self.rooms}, Жилая площадь ' \
  67. f'{self.life_square}, Совмещенный санузел {self.wc}, Этаж {self.floor},' \
  68. f' Окна выходят на {self.window}.'
  69.  
  70.  
  71. class CountryHouseList(list):
  72.  
  73. def __init__(self, name):
  74. self.name = name
  75.  
  76. def append(self, p_object):
  77. if isinstance(p_object, CountryHouse):
  78. super().append(p_object)
  79. else:
  80. raise TypeError(f"Invalid type {type(p_object)}")
  81.  
  82. def total_square(self):
  83. sum1 = 0
  84. for i in self:
  85. sum1 += i.life_square
  86. return sum1
  87.  
  88.  
  89. class ApartmentList(list):
  90.  
  91. def __init__(self, name):
  92. self.name = name
  93.  
  94. def extend(self, iterable):
  95. for i in iterable:
  96. if isinstance(i, Apartment):
  97. super().append(i)
  98.  
  99. def floor_view(self, floors, directions):
  100. fl = lambda x: floors[0] <= x.floor <= floors[-1] and x.window in directions
  101. view = list(filter(fl, self))
  102. for i in view:
  103. print(f'{i.window}: {i.floor}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement