示例#1
0
def square_area(side):
    """
    Calculate area of a square from side length.
    @param side: the side length
    @return: the area (units^2 from side)
    >>> square_area(4)
    16
    """
    if dim_validate(side):
        return side*side
    else:
        raise ValueError("side is les than 0: "+str(side))
示例#2
0
def square_perimeter(side: Number) -> Number:
    """
    Calculate perimeter of a square from side length.

    @param side: the side length
    @return: the perimeter (same units as side length)

    >>> square_perimeter(4)
    16
    """
    if dim_validate(side):
        return 4*side
    else:
        raise ValueError("side is les than 0: "+str(side))