101k views
4 votes
(Geometry: area of a regular polygon)

A 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 side: 6.5
The area of the polygon is 72.69017017488385
ANSWER SHOULD BE IN PYTHON CODING

User Eilish
by
4.9k points

1 Answer

5 votes

Answer:

Follows are the python code to this question:

import math as m #import package

n=int(input('Enter the number of sides:'))#defining n variable for input number of side

s= float(input('Enter the side: '))#defining s variable for input side value

area = (s*s *n)/(4 * (m.tan(m.pi/n)))#defining formula for calcaulting area

print (area)#print area

Output:

please find the attached file.

Explanation:

In the above code, firstly, we import the math package as m, and after that, two-variable "n and s" is defined, which uses for input integer and float value from the user end.

  • In the next step, we use the area formula that is already in the question.
  • In this formula, we modify some value and put the user input into the area formula, and print its value.
(Geometry: area of a regular polygon) A regular polygon is an n-sided polygon in which-example-1
User Lumio
by
5.4k points