From a6d302bcb15c7ecd490085114e2068f2a5145f6a Mon Sep 17 00:00:00 2001 From: Yousha Mahamuni <40205524+yousha806@users.noreply.github.com> Date: Tue, 3 Oct 2023 23:32:25 +0530 Subject: [PATCH 1/4] Update volume.py with volume of Icosahedron Added function to find volume of a regular Icosahedron --- maths/volume.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/maths/volume.py b/maths/volume.py index 721974e68b66..eb58f8db8ccf 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -468,6 +468,32 @@ def vol_torus(torus_radius: float, tube_radius: float) -> float: raise ValueError("vol_torus() only accepts non-negative values") return 2 * pow(pi, 2) * torus_radius * pow(tube_radius, 2) +def vol_icosahedron(tri_side :float) -> float: + """Calculate the Volume of an Icosahedron. + Wikipedia reference: https://en.wikipedia.org/wiki/Regular_icosahedron + + >>> vol_icosahedron(2.5) + 34.088984228514256 + >>> vol_icosahedron(10) + 2181.6949906249124 + >>> vol_icosahedron(5) + 272.71187382811405 + >>> vol_icosahedron(3.49) + 92.74068841203366 + >>> vol_icosahedron(0) + 0.0 + >>> vol_icosahedron(-1) + Traceback (most recent call last): + ... + ValueError: vol_icosahedron() only accepts non-negative values + >>> vol_icosahedron(-.2) + Traceback (most recent call last): + ... + ValueError: vol_icosahedron() only accepts non-negative values + """ + if tri_side < 0: + raise ValueError("vol_icosahedron() only accepts non-negative values") + return (pow(tri_side,3)*((3+pow(5,1/2))*5/12)) def main(): """Print the Results of Various Volume Calculations.""" @@ -489,6 +515,7 @@ def main(): print( f"Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1, 2, 3) = }" ) # ~= 28.3 + print(f"Icosahedron: {vol_icosahedron(2.5) = }") #~=34.09 if __name__ == "__main__": From fb525b8a7207b884d4d4c56999d87ae90d39837c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Oct 2023 18:09:51 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/volume.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/maths/volume.py b/maths/volume.py index eb58f8db8ccf..c477aa6305d4 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -468,10 +468,11 @@ def vol_torus(torus_radius: float, tube_radius: float) -> float: raise ValueError("vol_torus() only accepts non-negative values") return 2 * pow(pi, 2) * torus_radius * pow(tube_radius, 2) -def vol_icosahedron(tri_side :float) -> float: + +def vol_icosahedron(tri_side: float) -> float: """Calculate the Volume of an Icosahedron. Wikipedia reference: https://en.wikipedia.org/wiki/Regular_icosahedron - + >>> vol_icosahedron(2.5) 34.088984228514256 >>> vol_icosahedron(10) @@ -493,7 +494,8 @@ def vol_icosahedron(tri_side :float) -> float: """ if tri_side < 0: raise ValueError("vol_icosahedron() only accepts non-negative values") - return (pow(tri_side,3)*((3+pow(5,1/2))*5/12)) + return pow(tri_side, 3) * ((3 + pow(5, 1 / 2)) * 5 / 12) + def main(): """Print the Results of Various Volume Calculations.""" @@ -515,7 +517,7 @@ def main(): print( f"Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1, 2, 3) = }" ) # ~= 28.3 - print(f"Icosahedron: {vol_icosahedron(2.5) = }") #~=34.09 + print(f"Icosahedron: {vol_icosahedron(2.5) = }") # ~=34.09 if __name__ == "__main__": From d110493adc71fa135d4f141c8f80703f40651c01 Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Sun, 15 Oct 2023 22:30:18 -0400 Subject: [PATCH 3/4] Apply suggestions from code review --- maths/volume.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/volume.py b/maths/volume.py index c477aa6305d4..e1d390cac9fd 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -494,7 +494,7 @@ def vol_icosahedron(tri_side: float) -> float: """ if tri_side < 0: raise ValueError("vol_icosahedron() only accepts non-negative values") - return pow(tri_side, 3) * ((3 + pow(5, 1 / 2)) * 5 / 12) + return tri_side**3 * (3 + 5**0.5) * 5 / 12 def main(): From ba7027257e6d26f37c0b7510dbb0fa15bdad081d Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Sun, 15 Oct 2023 22:39:45 -0400 Subject: [PATCH 4/4] Update volume.py --- maths/volume.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/maths/volume.py b/maths/volume.py index e1d390cac9fd..b4df4e475783 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -473,21 +473,22 @@ def vol_icosahedron(tri_side: float) -> float: """Calculate the Volume of an Icosahedron. Wikipedia reference: https://en.wikipedia.org/wiki/Regular_icosahedron - >>> vol_icosahedron(2.5) - 34.088984228514256 - >>> vol_icosahedron(10) - 2181.6949906249124 - >>> vol_icosahedron(5) - 272.71187382811405 - >>> vol_icosahedron(3.49) - 92.74068841203366 + >>> from math import isclose + >>> isclose(vol_icosahedron(2.5), 34.088984228514256) + True + >>> isclose(vol_icosahedron(10), 2181.694990624912374) + True + >>> isclose(vol_icosahedron(5), 272.711873828114047) + True + >>> isclose(vol_icosahedron(3.49), 92.740688412033628) + True >>> vol_icosahedron(0) 0.0 >>> vol_icosahedron(-1) Traceback (most recent call last): ... ValueError: vol_icosahedron() only accepts non-negative values - >>> vol_icosahedron(-.2) + >>> vol_icosahedron(-0.2) Traceback (most recent call last): ... ValueError: vol_icosahedron() only accepts non-negative values