From 098a1b23459072623e36a9f9a79095efb72d2837 Mon Sep 17 00:00:00 2001 From: Gopesh Pandey Date: Sat, 17 Jan 2026 01:53:12 +0530 Subject: [PATCH 1/2] Create volume_of_torus.py --- maths/volume_of_torus.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 maths/volume_of_torus.py diff --git a/maths/volume_of_torus.py b/maths/volume_of_torus.py new file mode 100644 index 000000000000..ff28d88e021e --- /dev/null +++ b/maths/volume_of_torus.py @@ -0,0 +1,26 @@ +""" +Volume of a Torus +Board: https://en.wikipedia.org/wiki/Torus +""" +import math + +def volume_of_torus(major_radius: float, minor_radius: float) -> float: + """ + Calculate the volume of a torus. + + :param major_radius: Distance from the center of the tube to the center of the torus (R) + :param minor_radius: Radius of the tube (r) + :return: Volume of the torus + + >>> volume_of_torus(3, 1) + 59.21762640653615 + >>> volume_of_torus(5, 2) + 394.7841760435743 + """ + if major_radius < 0 or minor_radius < 0: + raise ValueError("Radii must be non-negative") + return 2 * (math.pi ** 2) * major_radius * (minor_radius ** 2) + +if __name__ == "__main__": + import doctest + doctest.testmod() From cda24f7714ea12461fa2dc69e0f4bb8da4ce235e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 Jan 2026 20:33:19 +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_of_torus.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/maths/volume_of_torus.py b/maths/volume_of_torus.py index ff28d88e021e..3f930f977b11 100644 --- a/maths/volume_of_torus.py +++ b/maths/volume_of_torus.py @@ -2,8 +2,10 @@ Volume of a Torus Board: https://en.wikipedia.org/wiki/Torus """ + import math + def volume_of_torus(major_radius: float, minor_radius: float) -> float: """ Calculate the volume of a torus. @@ -11,7 +13,7 @@ def volume_of_torus(major_radius: float, minor_radius: float) -> float: :param major_radius: Distance from the center of the tube to the center of the torus (R) :param minor_radius: Radius of the tube (r) :return: Volume of the torus - + >>> volume_of_torus(3, 1) 59.21762640653615 >>> volume_of_torus(5, 2) @@ -19,8 +21,10 @@ def volume_of_torus(major_radius: float, minor_radius: float) -> float: """ if major_radius < 0 or minor_radius < 0: raise ValueError("Radii must be non-negative") - return 2 * (math.pi ** 2) * major_radius * (minor_radius ** 2) + return 2 * (math.pi**2) * major_radius * (minor_radius**2) + if __name__ == "__main__": import doctest + doctest.testmod()