Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check1(rooms, life_square, is_wc):
- rms = isinstance(rooms, int) and rooms >= 0
- lsq = (isinstance(life_square, int) or isinstance(life_square, float)) and life_square >= 0
- wc = isinstance(is_wc, bool)
- return rms and lsq and wc
- def check2(floors, area_square):
- flr = isinstance(floors, int) and floors > 0
- ars = (isinstance(area_square, int) or isinstance(area_square, float)) and area_square >= 0
- return flr and ars
- def check3(floor, window):
- fl = isinstance(floor, int) and 1 <= floor <= 15
- wd = isinstance(window, str) and window in 'NSEW'
- return fl and wd
- def Valuer():
- raise ValueError("Invalid value")
- class HouseScheme:
- def __init__(self, rooms, life_square, is_wc):
- ch1 = check1(rooms, life_square, is_wc)
- if ch1:
- self.rooms = rooms
- self.life_square = life_square
- self.wc = is_wc
- else:
- Valuer()
- class CountryHouse(HouseScheme):
- def __init__(self, rooms, life_square, is_wc, floors, area_square):
- ch2 = check2(floors, area_square)
- if ch2:
- super().__init__(rooms, life_square, is_wc)
- self.floors = floors
- self.area_square = area_square
- else:
- Valuer()
- def __str__(self):
- return f"Country House: Количество жилых комнат {self.rooms}, Жилая площадь" \
- f" {self.life_square}, Совмещенный санузел {self.wc}, Количество этажей " \
- f"{self.floors}, Площадь участка {self.area_square}."
- def __eq__(self, other):
- return self.life_square == other.life_square and self.area_square == other.area_square and \
- abs(self.floors - other.floors) <= 1
- class Apartment(HouseScheme):
- def __init__(self, rooms, life_square, is_wc, floor, window):
- ch3 = check3(floor, window)
- if ch3:
- super().__init__(rooms, life_square, is_wc)
- self.floor = floor
- self.window = window
- else:
- Valuer()
- def __str__(self):
- return f'Apartment: Количество жилых комнат {self.rooms}, Жилая площадь ' \
- f'{self.life_square}, Совмещенный санузел {self.wc}, Этаж {self.floor},' \
- f' Окна выходят на {self.window}.'
- class CountryHouseList(list):
- def __init__(self, name):
- self.name = name
- def append(self, p_object):
- if isinstance(p_object, CountryHouse):
- super().append(p_object)
- else:
- raise TypeError(f"Invalid type {type(p_object)}")
- def total_square(self):
- sum1 = 0
- for i in self:
- sum1 += i.life_square
- return sum1
- class ApartmentList(list):
- def __init__(self, name):
- self.name = name
- def extend(self, iterable):
- for i in iterable:
- if isinstance(i, Apartment):
- super().append(i)
- def floor_view(self, floors, directions):
- fl = lambda x: floors[0] <= x.floor <= floors[-1] and x.window in directions
- view = list(filter(fl, self))
- for i in view:
- print(f'{i.window}: {i.floor}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement