This Python program calculates the area of a regular polygon.
The user is prompted to enter the length of one side and the total number of sides.
Using a geometric formula, the program computes and displays the area.
The code is formatted for smooth integration into a webpage using the specified HTML structure.
import math
side_length = float(input("Please enter the length of one side: "))
num_sides = int(input("Please enter the number of sides: "))
area = (num_sides * side_length ** 2) / (4 * math.tan(math.pi / num_sides))
print("The area of the regular polygon is:", area)
Please enter the length of one side: 5
Please enter the number of sides: 6
The area of the regular polygon is: 64.9519052838329
Here’s how the program works:
- It uses the math
module to access pi
and the tan()
function
- The formula used is:
(n × s²) ÷ (4 × tan(π ÷ n))
Where n
is the number of sides and s
is the side length
- The result is printed using the print()
function