Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Building Base by gyahun_dash
from itertools import product
from operator import attrgetter
class Building(object): # W to E: width, N to S: depth
def __init__(self, south, west, width, depth, height=10):
self.south, self.west = south, west
self.width, self.depth, self.height = width, depth, height
self.north, self.east = south + depth, west + width
def corners(self):
pairs = product(('south', 'north'), ('west', 'east'))
return {'-'.join(p): list(attrgetter(*p)(self)) for p in pairs}
def area(self):
return self.width * self.depth
def volume(self):
return self.area() * self.height
def __repr__(self):
txt = 'Building({0.south}, {0.west}, {0.width}, {0.depth}, {0.height})'
return txt.format(self)
Nov. 5, 2014
Comments: