Python ProgrammingPython Programming

Calculate Area of a Regular Polygon

A polygon is regular if its sides are all the same length and the angles between all of the adjacent sides are equal. Write a program in python that reads length of each side of Polygon, number of sides and then displays the area of a regular polygon constructed from these values.
##
#Python's program to calculate the Area of Polygon.
##

from math import tan,pi

#Define the constant
GRAVITY = 9.8	

#Read the input from user
length	= float(input("Enter the length of each side of Polygon (in meters): "))
number	= int(input("Enter the number of sides: "))

#Calculate the area of Polygon
area = (number * length ** 2)/(4 * tan(pi/number))

#Display the result
print("The area of Polygon is %.2f " % area)
Sample output of above program.
C:\Python\programs>python program.py
Enter the length of each side of Polygon (in meters): 78
Enter the number of sides: 6
The area of Polygon is 15806.70

C:\Python\programs>