Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Building Base by Sim0000
class Building():
def __init__(self, south, west, width_we, width_ns, height=10):
"""Returns a new Building instance with the South-West corner at [south, west]
coordinates, the size is width_WE by width_NS and the height of the building
is height. "height" is a positive number with a default value of 10. """
self.south = south
self.west = west
self.width_we = width_we
self.width_ns = width_ns
self.height = height
def corners(self):
"""Returns a dictionary with the coordinates of the building corners.
The dictionary has following keys: "north-west", "north-east", "south-west",
"south-east". The values are lists or tuples with two numbers."""
north = self.south + self.width_ns
east = self.west + self.width_we
return {
'north-west' : [north, self.west],
'south-west' : [self.south, self.west],
'north-east' : [north, east],
'south-east' : [self.south, east]
}
def area(self):
"Returns the area of the building."
return self.width_we * self.width_ns
def volume(self):
"Returns the volume of the building."
return self.area() * self.height
def __repr__(self):
"""This is a string representation of the Building. This method is used for
"print" or "str" conversation. Returns the string in the following view:
"Building({south}, {west}, {width_we}, {width_ns}, {height})" """
return 'Building({}, {}, {}, {}, {})'.format(
self.south, self.west, self.width_we, self.width_ns, self.height)
Nov. 4, 2014
Comments: