Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Building Base by quis20
class Building:
height = 10
south = 0
east = 0
width_WE = 0
width_NS = 0
height_str = ""
south_str = ""
east_str = ""
width_WE_str = ""
width_NS_str = ""
def __init__(self, south, west, width_WE, width_NS, height=10):
self.south = south
self.west = west
self.width_WE = width_WE
self.width_NS = width_NS
self.height = height
self.south_str = str(south)
self.west_str = str(west)
self.width_WE_str = str(width_WE)
self.width_NS_str = str(width_NS)
self.height_str = str(height)
def corners(self):
corners_calc = {"north-west": [0,0], "north-east": [0,0], "south-west": [0,0], "south-east": [0,0]}
corners_calc["south-west"] = [self.south, self.west]
corners_calc["north-west"] = [self.south+self.width_NS, self.west]
corners_calc["south-east"] = [self.south, self.west+self.width_WE]
corners_calc["north-east"] = [self.south+self.width_NS, self.west+self.width_WE]
return corners_calc
raise NotImplementedError
def area(self):
return self.width_NS*self.width_WE
raise NotImplementedError
def volume(self):
return self.area()*self.height
raise NotImplementedError
def __repr__(self):
return ("Building(%s, %s, %s, %s, %s)" % (self.south_str, self.west_str, self.width_WE_str, self.width_NS_str, self.height_str))
raise NotImplementedError
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 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"
Jan. 24, 2016
Comments: