This library provides functions to calculate the area and perimeter of various geometric shapes.
-
Area:
- Formula:
S = pi R^2 - Function: circle.area(r)
- Parameters:
- r (int, float): The radius of the circle.
- Returns: The area of the circle.
- Formula:
-
Perimeter:
- Formula:
P = 2pi R - Function: circle.perimeter(r)
- Parameters:
- r (int, float): The radius of the circle.
- Returns: The perimeter of the circle.
- Formula:
-
Area:
- Formula:
S = ab - Function: rectangle.area(a, b)
- Parameters:
- a (int, float): One side of the rectangle.
- b (int, float): The other side of the rectangle.
- Returns: The area of the rectangle.
- Formula:
-
Perimeter:
- Formula:
P = 2a + 2b - Function: rectangle.perimeter(a, b)
- Parameters:
- a (int, float): One side of the rectangle.
- b (int, float): The other side of the rectangle.
- Returns: The perimeter of the rectangle.
- Formula:
-
Area:
- Formula:
S = a^2 - Function: square.area(a)
- Parameters:
- a (int, float): The side of the square.
- Returns: The area of the square.
- Formula:
-
Perimeter:
- Formula:
P = 4a - Function: square.perimeter(a)
- Parameters:
- a (int, float): The side of the square.
- Returns: The perimeter of the square.
- Formula:
-
Area:
- Formula:
S = ah/2 - Function: triangle.area(a, h)
- Parameters:
- a (int, float): The base of the triangle.
- h (int, float): The height of the triangle.
- Returns: The area of the triangle.
- Formula:
-
Perimeter:
- Formula:
P = a + b + c - Function: triangle.perimeter(a, b, c)
- Parameters:
- a, b, c (int, float): The lengths of the sides of the triangle.
- Returns: The perimeter of the triangle.
- Formula:
-
Area:
- Formula:
S = (a + b)h/2 - Function: trapezoid.area(a, b, h)
- Parameters:
- a, b (int, float): The lengths of the two bases.
- h (int, float): The height of the trapezoid.
- Returns: The area of the trapezoid.
- Formula:
-
Perimeter:
- Formula:
P = a + b + c + d - Function: trapezoid.perimeter(a, b, c, d)
- Parameters:
- a, b, c, d (int, float): The lengths of all four sides.
- Returns: The perimeter of the trapezoid.
- Formula:
-
Area:
- Formula:
S = d_1 * d_2/2 - Function: rhombus.area(d1, d2)
- Parameters:
- d1, d2 (int, float): The lengths of the diagonals.
- Returns: The area of the rhombus.
- Formula:
-
Perimeter:
- Formula:
P = 4a - Function: rhombus.perimeter(a)
- Parameters:
- a (int, float): The length of a side.
- Returns: The perimeter of the rhombus.
- Formula:
-
Area:
- Formula:
S = a * h - Function: parallelogram.area(a, h)
- Parameters:
- a (int, float): The length of a base.
- h (int, float): The height.
- Returns: The area of the parallelogram.
- Formula:
-
Perimeter:
- Formula:
P = 2(a + b) - Function: parallelogram.perimeter(a, b)
- Parameters:
- a, b (int, float): The lengths of the sides.
- Returns: The perimeter of the parallelogram.
- Formula:
-
Area:
- Formula:
S = pi a b - Function: ellipse.area(a, b)
- Parameters:
- a, b (int, float): The semi-major and semi-minor axes.
- Returns: The area of the ellipse.
- Formula:
-
Perimeter:
- Approximate formula using Ramanujan's approximation:
P = approx pi [3(a + b) - sqrt{(3a + b)(a + 3b)}] - Function: ellipse.perimeter(a, b)
- Parameters:
- a, b (int, float): The semi-major and semi-minor axes.
- Returns: The approximate perimeter of the ellipse.
- Approximate formula using Ramanujan's approximation:
To run tests for this library:
- Make sure you have Python installed on your machine.
- Navigate to the directory containing your tests.
- Run the following command:
python3 -m unittest discover -s tests