-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolygon.py
More file actions
29 lines (21 loc) · 787 Bytes
/
polygon.py
File metadata and controls
29 lines (21 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 14 17:08:56 2017
@author: thelma
"""
def polysum(n,s):
"""
Input: Positive integers n and s. n is the number of sides of the
polygon and is larger than 2, s is the length of each side of the polygon.
Returns a positive integer, the sum of the area and the square of the
perimeter of the polygon, rounded to 4 decimal places.
"""
# Import math library.
import math
# Define the area of the polgon as area.
area = (0.25*n*s**2) / math.tan(math.pi/n)
# Define the square of the perimeter as squarePeri.
squarePeri = (n*s) ** 2
# Return sum of area and squarePeri rounded to 4 decimal places.
return round(area+squarePeri, 4)