From 910216e972c51760833b2bfb5c3ff72f53e8cd7f Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 13:52:51 -0700 Subject: [PATCH 01/10] add surface area class --- maths/surface_area.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 maths/surface_area.py diff --git a/maths/surface_area.py b/maths/surface_area.py new file mode 100644 index 000000000000..2da6d1e87260 --- /dev/null +++ b/maths/surface_area.py @@ -0,0 +1,31 @@ +""" +Find Surface Area of Various Shapes. + +Wikipedia reference: https://en.wikipedia.org/wiki/Surface_area +""" +from math import pi, pow +from typing import Union + +def surface_area_cube(side_length: Union[int, float]) -> float: + """ + Calculate the Surface Area of a Cube. + + >>> surface_area_cube(1) + 6.0 + >>> surface_area_cube(3) + 54.0 + """ + return 6 * pow(side_length, 2) + +def surface_area_sphere(radius: float) -> float: + """ + Calculate the Surface Area of a Sphere. + Wikipedia reference: https://en.wikipedia.org/wiki/Sphere + :return 4 * pi * r^2 + + >>> vol_sphere(5) + 314.1592653589793 + >>> vol_sphere(1) + 12.566370614359172 + """ + return 4 * pi * pow(radius, 2) \ No newline at end of file From d472d706c824620edbe38faa407cc13c90cd5181 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 13:54:55 -0700 Subject: [PATCH 02/10] add new line to end of file --- maths/surface_area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/surface_area.py b/maths/surface_area.py index 2da6d1e87260..7a8952a8d854 100644 --- a/maths/surface_area.py +++ b/maths/surface_area.py @@ -28,4 +28,4 @@ def surface_area_sphere(radius: float) -> float: >>> vol_sphere(1) 12.566370614359172 """ - return 4 * pi * pow(radius, 2) \ No newline at end of file + return 4 * pi * pow(radius, 2) From b0816a5232add2cd1b648fda5519fb3d4dc03c9f Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 14:26:39 -0700 Subject: [PATCH 03/10] move surface area class into area class --- maths/area.py | 31 +++++++++++++++++++++++++++++-- maths/surface_area.py | 31 ------------------------------- 2 files changed, 29 insertions(+), 33 deletions(-) delete mode 100644 maths/surface_area.py diff --git a/maths/area.py b/maths/area.py index 0621bf5dd809..0ee79e7a03f3 100644 --- a/maths/area.py +++ b/maths/area.py @@ -1,10 +1,35 @@ """ Find the area of various geometric shapes """ - import math +def surface_area_cube(side_length: Union[int, float]) -> float: + """ + Calculate the Surface Area of a Cube. + + >>> surface_area_cube(1) + 6.0 + >>> surface_area_cube(3) + 54.0 + """ + return 6 * pow(side_length, 2) + + +def surface_area_sphere(radius: float) -> float: + """ + Calculate the Surface Area of a Sphere. + Wikipedia reference: https://en.wikipedia.org/wiki/Sphere + :return 4 * pi * r^2 + + >>> vol_sphere(5) + 314.1592653589793 + >>> vol_sphere(1) + 12.566370614359172 + """ + return 4 * pi * pow(radius, 2) + + def area_rectangle(base, height): """ Calculate the area of a rectangle @@ -73,7 +98,9 @@ def main(): 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)=}") if __name__ == "__main__": main() diff --git a/maths/surface_area.py b/maths/surface_area.py deleted file mode 100644 index 7a8952a8d854..000000000000 --- a/maths/surface_area.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Find Surface Area of Various Shapes. - -Wikipedia reference: https://en.wikipedia.org/wiki/Surface_area -""" -from math import pi, pow -from typing import Union - -def surface_area_cube(side_length: Union[int, float]) -> float: - """ - Calculate the Surface Area of a Cube. - - >>> surface_area_cube(1) - 6.0 - >>> surface_area_cube(3) - 54.0 - """ - return 6 * pow(side_length, 2) - -def surface_area_sphere(radius: float) -> float: - """ - Calculate the Surface Area of a Sphere. - Wikipedia reference: https://en.wikipedia.org/wiki/Sphere - :return 4 * pi * r^2 - - >>> vol_sphere(5) - 314.1592653589793 - >>> vol_sphere(1) - 12.566370614359172 - """ - return 4 * pi * pow(radius, 2) From af4c70feee2633e0256835dd92602414130ad038 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 14:31:56 -0700 Subject: [PATCH 04/10] add missing import --- maths/area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index 0ee79e7a03f3..addc1820b091 100644 --- a/maths/area.py +++ b/maths/area.py @@ -2,7 +2,7 @@ Find the area of various geometric shapes """ import math - +from typing import Union def surface_area_cube(side_length: Union[int, float]) -> float: """ From 39eaac47bca9eee2e296e28a6726fac742fdde5c Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 14:36:01 -0700 Subject: [PATCH 05/10] added pi import --- maths/area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index addc1820b091..c2eead35d59b 100644 --- a/maths/area.py +++ b/maths/area.py @@ -1,7 +1,7 @@ """ Find the area of various geometric shapes """ -import math +import math import pi from typing import Union def surface_area_cube(side_length: Union[int, float]) -> float: From 531837c32c21c3a90d16bbd62355245a27ea6c68 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 14:36:29 -0700 Subject: [PATCH 06/10] fix typo --- maths/area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index c2eead35d59b..3bb00663e0be 100644 --- a/maths/area.py +++ b/maths/area.py @@ -1,7 +1,7 @@ """ Find the area of various geometric shapes """ -import math import pi +from math import pi from typing import Union def surface_area_cube(side_length: Union[int, float]) -> float: From acb220f369c1aa37f45f21f02f54d1e88376a8af Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 14:38:17 -0700 Subject: [PATCH 07/10] added blank line --- maths/area.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/area.py b/maths/area.py index 3bb00663e0be..28110a91feae 100644 --- a/maths/area.py +++ b/maths/area.py @@ -4,6 +4,7 @@ from math import pi from typing import Union + def surface_area_cube(side_length: Union[int, float]) -> float: """ Calculate the Surface Area of a Cube. From 80066dc3df4d3143ec83145739eca5758c569bf9 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 14:54:26 -0700 Subject: [PATCH 08/10] fixed more import issues --- maths/area.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index 28110a91feae..6e3e9699d6c9 100644 --- a/maths/area.py +++ b/maths/area.py @@ -88,7 +88,7 @@ def area_circle(radius): >> area_circle(20) 1256.6370614359173 """ - return math.pi * radius * radius + return pi * radius * radius def main(): @@ -103,5 +103,6 @@ def main(): print(f"Cube: {surface_area_cube(20)=}") print(f"Sphere: {surface_area_sphere(20)=}") + if __name__ == "__main__": main() From 1b289295760f86c465a1aca81c457cb13ed86b29 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 15:03:44 -0700 Subject: [PATCH 09/10] comment fix --- maths/area.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/area.py b/maths/area.py index 6e3e9699d6c9..3bc01a8c1b1f 100644 --- a/maths/area.py +++ b/maths/area.py @@ -23,9 +23,9 @@ def surface_area_sphere(radius: float) -> float: Wikipedia reference: https://en.wikipedia.org/wiki/Sphere :return 4 * pi * r^2 - >>> vol_sphere(5) + >>> surface_area_sphere(5) 314.1592653589793 - >>> vol_sphere(1) + >>> surface_area_sphere(1) 12.566370614359172 """ return 4 * pi * pow(radius, 2) From 540cd149b1551f9b3b8d5168d7a21441a3c51a96 Mon Sep 17 00:00:00 2001 From: lance-pyles Date: Mon, 6 Jul 2020 15:12:48 -0700 Subject: [PATCH 10/10] comment fixes --- maths/area.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/area.py b/maths/area.py index 3bc01a8c1b1f..a14fe130475f 100644 --- a/maths/area.py +++ b/maths/area.py @@ -10,9 +10,9 @@ def surface_area_cube(side_length: Union[int, float]) -> float: Calculate the Surface Area of a Cube. >>> surface_area_cube(1) - 6.0 + 6 >>> surface_area_cube(3) - 54.0 + 54 """ return 6 * pow(side_length, 2)