From 3b3253b2d87e4673fd87c7ec825644a3d02d1fd9 Mon Sep 17 00:00:00 2001 From: kvadrik <41710943+kvadrik@users.noreply.github.com> Date: Wed, 18 Feb 2026 23:19:08 +0200 Subject: [PATCH 1/2] Update volume.py --- maths/volume.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/maths/volume.py b/maths/volume.py index 1715c9c300d5..a31c9d53e381 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -509,6 +509,30 @@ 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_octahedron(oct_side: float) -> float: + """ + | Calculate the Volume of an Octahedron. + | Wikipedia reference: https://en.wikipedia.org/wiki/Regular_octahedron + + >>> from math import isclose + >>> isclose(vol_octahedron(2.5), 7.36569563735987) + True + >>> isclose(vol_octahedron(10), 471.40452079103168) + True + >>> isclose(vol_octahedron(5), 58.92556509887896) + True + >>> isclose(vol_octahedron(3.5), 20.21146882891548) + True + >>> vol_octahedron(0) + 0.0 + >>> vol_octahedron(-1) + Traceback (most recent call last): + ... + ValueError: vol_octahedron() only accepts non-negative values + """ + if oct_side < 0: + raise ValueError("vol_octahedron() only accepts non-negative values") + return oct_side**3 * 2**0.5 / 3 def vol_icosahedron(tri_side: float) -> float: """ @@ -560,6 +584,7 @@ def main(): print( f"Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1, 2, 3) = }" ) # ~= 28.3 + print(f"Octahedron: {vol_octahedron(2.5) = }") # ~=7.37 print(f"Icosahedron: {vol_icosahedron(2.5) = }") # ~=34.09 From 4134ea75bc005c9b99c8c7ca5c162fa804d8c34f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Feb 2026 21:21:47 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/volume.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/maths/volume.py b/maths/volume.py index a31c9d53e381..f48d388b423e 100644 --- a/maths/volume.py +++ b/maths/volume.py @@ -509,6 +509,7 @@ 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_octahedron(oct_side: float) -> float: """ | Calculate the Volume of an Octahedron. @@ -534,6 +535,7 @@ def vol_octahedron(oct_side: float) -> float: raise ValueError("vol_octahedron() only accepts non-negative values") return oct_side**3 * 2**0.5 / 3 + def vol_icosahedron(tri_side: float) -> float: """ | Calculate the Volume of an Icosahedron. @@ -584,7 +586,7 @@ def main(): print( f"Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1, 2, 3) = }" ) # ~= 28.3 - print(f"Octahedron: {vol_octahedron(2.5) = }") # ~=7.37 + print(f"Octahedron: {vol_octahedron(2.5) = }") # ~=7.37 print(f"Icosahedron: {vol_icosahedron(2.5) = }") # ~=34.09