Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Building Base by Mahoter
class Building:
def __init__(self, south, west, width_WE, width_NS, height=10):
self.s = south
self.w = west
self.szer = width_WE
self.dlug = width_NS
self.wys = height
def corners(self):
res = {}
northwest = [self.s+self.dlug , self.w]
southwest = [self.s , self.w ]
southeast = [self.s , self.w + self.szer]
northeast = [self.s+self.dlug , self.w+self.szer]
res["north-east"] = [self.s+self.dlug , self.w+self.szer]
res["north-west"] = [self.s+self.dlug , self.w]
res["south-east"] = [self.s , self.w + self.szer]
res["south-west"] = [self.s , self.w ]
return res
def area(self):
return self.szer*self.dlug
def volume(self):
return self.szer*self.dlug*self.wys
def __repr__(self):
a = 'Building('+str(self.s)+', '+str(self.w)+', '+str(self.szer)+', '+str(self.dlug)+', '+str(self.wys)+')'
return a
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. 17, 2016