Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Building Base by AlokShrestha
# migrated from python 2.7
class Building:
def __init__(self, south, west, width_WE, width_NS, height=10):
self.s = south
self.w = west
self.w_WE = width_WE
self.w_NS = width_NS
self.h = height
def corners(self):
return {"north-west" : [self.w_NS + self.s , self.w],
"north-east" : [self.w_NS + self.s , self.w_WE + self.w],
"south-west" : [self.s, self.w],
"south-east" : [self.s, self.w_WE + self.w]}
def area(self):
return self.w_NS * self.w_WE
def volume(self):
return self.w_NS * self.w_WE * self.h
def __repr__(self):
return "%s(%r, %r, %r, %r, %r)" % (self.__class__, self.s, self.w, self.w_WE, self.w_NS, self.h)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
def json_dict(d):
return dict((k, list(v)) for k, v in list(d.items()))
b = Building(1, 2, 2, 3)
b2 = Building(1, 2, 2, 3, 5)
assert json_dict(b.corners()) == {'north-east': [4, 4], 'south-east': [1, 4],
'south-west': [1, 2], 'north-west': [4, 2]}, "Corners"
assert b.area() == 6, "Area"
assert b.volume() == 60, "Volume"
assert b2.volume() == 30, "Volume2"
assert str(b) == "Building(1, 2, 2, 3, 10)", "String"
June 16, 2016