Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
12-lines with lambda methods (except init) solution in Creative category for Building Base by Phil15
class Building:
def __init__(self, south, west, width_WE, width_NS, height=10):
self.south, self.west = south, west
self.width_we, self.width_ns, self.height = width_WE, width_NS, height
north = property(lambda self: self.south + self.width_ns)
east = property(lambda self: self.west + self.width_we)
corners = lambda self: {f'{ns}-{we}': (getattr(self, ns), getattr(self, we))
for ns in('north','south') for we in('west','east')}
area = lambda self: self.width_we * self.width_ns
volume = lambda self: self.area() * self.height
__str__ = __repr__ = lambda self: "Building" + str(
(self.south, self.west, self.width_we, self.width_ns, self.height))
Sept. 22, 2018
Comments: