From b3950035a61298704a5f19420d4746a0f12c71a0 Mon Sep 17 00:00:00 2001 From: lance-pyles <36748284+lance-pyles@users.noreply.github.com> Date: Wed, 22 Jul 2020 15:49:34 -0700 Subject: [PATCH] update variable names for consistency using standard formula terms; (#2223) * update variable names for consistency using standard formula terms; fix flake8 syntax errors; fix doctests; * tweak to variable name --- maths/area.py | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/maths/area.py b/maths/area.py index a14fe1304..f317118ad 100644 --- a/maths/area.py +++ b/maths/area.py @@ -31,14 +31,14 @@ def surface_area_sphere(radius: float) -> float: return 4 * pi * pow(radius, 2) -def area_rectangle(base, height): +def area_rectangle(length, width): """ Calculate the area of a rectangle - >> area_rectangle(10,20) + >>> area_rectangle(10,20) 200 """ - return base * height + return length * width def area_square(side_length): @@ -48,24 +48,24 @@ def area_square(side_length): >>> area_square(10) 100 """ - return side_length * side_length + return pow(side_length, 2) -def area_triangle(length, breadth): +def area_triangle(base, height): """ Calculate the area of a triangle >>> area_triangle(10,10) 50.0 """ - return 1 / 2 * length * breadth + return (base * height) / 2 def area_parallelogram(base, height): """ Calculate the area of a parallelogram - >> area_parallelogram(10,20) + >>> area_parallelogram(10,20) 200 """ return base * height @@ -75,8 +75,8 @@ def area_trapezium(base1, base2, height): """ Calculate the area of a trapezium - >> area_trapezium(10,20,30) - 450 + >>> area_trapezium(10,20,30) + 450.0 """ return 1 / 2 * (base1 + base2) * height @@ -85,24 +85,29 @@ def area_circle(radius): """ Calculate the area of a circle - >> area_circle(20) + >>> area_circle(20) 1256.6370614359173 """ - return pi * radius * radius + return pi * pow(radius, 2) def main(): print("Areas of various geometric shapes: \n") - print(f"Rectangle: {area_rectangle(10, 20)=}") - print(f"Square: {area_square(10)=}") - print(f"Triangle: {area_triangle(10, 10)=}") - print(f"Parallelogram: {area_parallelogram(10, 20)=}") - print(f"Trapezium: {area_trapezium(10, 20, 30)=}") - print(f"Circle: {area_circle(20)=}") - print("Surface Areas of various geometric shapes: \n") - print(f"Cube: {surface_area_cube(20)=}") - print(f"Sphere: {surface_area_sphere(20)=}") + print(f"Rectangle: {area_rectangle(10, 20)}") + print(f"Square: {area_square(10)}") + print(f"Triangle: {area_triangle(10, 10)}") + print(f"Parallelogram: {area_parallelogram(10, 20)}") + print(f"Trapezium: {area_trapezium(10, 20, 30)}") + print(f"Circle: {area_circle(20)}") + print("\nSurface Areas of various geometric shapes: \n") + print(f"Cube: {surface_area_cube(20)}") + print(f"Sphere: {surface_area_sphere(20)}") if __name__ == "__main__": + + import doctest + + doctest.testmod(verbose=True) # verbose so we can see methods missing tests + main()