Advertisement
Icomey

Untitled

Feb 27th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from math import pi, tan
  2.  
  3. def polysum(n, s):
  4.     '''
  5.    Input integer n is number of sides of a regular polygon
  6.    Input: integer s is length of sides of a regular polygon
  7.    Returns the sum of the area and the square of the perimeter of the polygon
  8.    rounded to 4 decimal places
  9.    '''
  10.     def area(n, s):
  11.         '''
  12.        Input integer n is number of sides of a regular polygon
  13.        Input: integer s is length of sides of a regular polygon
  14.        Returns the area of the polygon
  15.        '''
  16.         numerator = 0.25 * n * s ** 2
  17.         denominator = tan(pi / n)
  18.         return numerator / denominator
  19.  
  20.     def perimSquare(n, s):
  21.         '''
  22.        Input: integer n is number of sides of a regular polygon
  23.        Input: integer s is length of sides of a regular polygon
  24.        Returns the square of the perimeter of the polygon
  25.        '''
  26.         return (n * s) ** 2
  27.  
  28.     a = area(n, s)
  29.     p = perimSquare(n, s)
  30.     return round(a + p, 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement