Program - function to print the regular polygon area


Topic: Program - function to print the regular polygon area

Solution

def polygon_area(side_length=1, side=3):
    from math import tan
    if side_length <= 0:
        raise ValueError("How come Side is zero.")
    else:
        if side <= 0 or side >=7:
            raise NotImplementedError 
        elif side in ( 2 , 1 ):
            raise ValueError("No Polygon of Side 1 & 2 Exists")
        elif side == 3:
            return side_length*side_length*side/4*tan(180/side)
        elif side == 4:
            return side_length*side_length
        elif side == 5:
            return side_length*side_length*side/4*tan(180/side)
        elif side == 6:
            return side_length*side_length*side/4*tan(180/side)



List all Python Programs