Polygon Area
Source: May 2025, Task 1 (DTU 02002/02003). Study solution — not an official answer key.
Problem
The area of a regular polygon with n sides of length s is:
A = (n * s2) / (4 * tan(π / n))
Write polygon_area(n, s) that returns this area as a float.
n: int — number of sidess: float — side length- Returns: float — polygon area
Example
>>> polygon_area(5, 4.31)
31.9597602410807
Approach
Use math.tan and math.pi. Apply the formula directly.
Solution
Show solution Hide solution
Solution
import math
def polygon_area(n, s):
return (n * s ** 2) / (4 * math.tan(math.pi / n))