Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class HouseScheme():
- def __init__(self, liverooms, livespace, wc):
- if livespace >= 0 and type(wc) == bool:
- self.liverooms = liverooms
- self.livespace = livespace
- self.wc = wc
- else:
- raise ValueError('Invalid value')
- class CountryHouse(HouseScheme): # Класс должен наследоваться от HouseScheme
- def __init__(self, liverooms, livespace, wc, floors, yard):
- super().__init__(liverooms, livespace, wc)
- self.floors = floors
- self.yard = yard
- def __str__(self):
- return f'Country House: Количество жилых комнат {self.liverooms}, Жилая площадь {self.livespace}, Совмещенный санузел {self.wc}, Количество этажей {self.floors}, Площадь участка {self.yard}.'
- def __eq__(self, other):
- if (self.livespace == other.livespace) and (self.yard == other.yard) and ((self.floors - 1) <= (other.floors) <= (self.floors + 1)):
- return True
- else:
- return False
- class Apartment(HouseScheme): # Класс должен наследоваться от HouseScheme
- def __init__(self, liverooms, livespace, wc, floors, direction):
- super().__init__(liverooms, livespace, wc)
- if floors >= 1 and floors <= 15 and (direction == 'N' or direction == 'S' or direction == 'W' or direction == 'E'):
- self.floors = floors
- self.direction = direction
- else:
- raise ValueError('Invalid value')
- def __str__(self):
- return f'Apartment: Количество жилых комнат {self.liverooms}, Жилая площадь {self.livespace}, Совмещенный санузел {self.wc}, Этаж {self.floors}, Окна выходят на {self.direction}.'
- class CountryHouseList(list): # список деревенских домов -- "деревня", наследуется от класса list
- def __init__(self, name):
- super().__init__()
- self.name = name
- def append(self, p_object):
- if issubclass(type(p_object), CountryHouse):
- super().append(p_object)
- else:
- raise TypeError("Invalid type "+ str(type(p_object)))
- def total_square(self):
- total_square = 0
- for i in self:
- total_square += i.livespace #Посчитать общую жилую площадь
- return total_square
- class ApartmentList(list): # список городских квартир -- ЖК, наследуется от класса list
- def __init__(self, name):
- super().__init__()
- self.name = name
- def extend(self, iterable):
- super().extend(list(filter(lambda x: type(x) == Apartment, iterable)))
- def floor_view(self, floors, directions):
- for direct_floor in list(filter(lambda x: floors[0] <= x.floors <= floors[1] and x.direction in directions, self)):
- print('{}: {}'.format(direct_floor.direction, direct_floor.floors))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement