To find the area of a regular polygon in python, we need to know the length of one side of the polygon (s) and the number of sides (n).
We can use the following formula to calculate the area:
main.py35 chars2 lines
Here is the python code implementing the above formula:
main.py284 chars11 lines
Output:
main.py81 chars2 lines
Note that we have used the math
module to access the value of pi and the tangent function. Also, the output may have a small error due to the precision of floating-point arithmetic.
gistlibby LogSnag