import math
s = float(input('Enter the length of a side '))
n = int(input('Enter the number of sides '))
area = (n*s**2)/(4*math.tan(math.pi/n))
print(f'The area of the polygon is {area}')
Richard P.
asked 04/02/24A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is
area = (n * s^2) / (4 * tan(PI / n))
Here, s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area.
Sample Run
Enter the number of sides: 5
Enter the length of a side: 6.5
The area of the polygon is 72.69017017488385
import math
s = float(input('Enter the length of a side '))
n = int(input('Enter the number of sides '))
area = (n*s**2)/(4*math.tan(math.pi/n))
print(f'The area of the polygon is {area}')
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.