We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c88735 commit 098a1b2Copy full SHA for 098a1b2
1 file changed
maths/volume_of_torus.py
@@ -0,0 +1,26 @@
1
+"""
2
+Volume of a Torus
3
+Board: https://en.wikipedia.org/wiki/Torus
4
5
+import math
6
+
7
+def volume_of_torus(major_radius: float, minor_radius: float) -> float:
8
+ """
9
+ Calculate the volume of a torus.
10
11
+ :param major_radius: Distance from the center of the tube to the center of the torus (R)
12
+ :param minor_radius: Radius of the tube (r)
13
+ :return: Volume of the torus
14
15
+ >>> volume_of_torus(3, 1)
16
+ 59.21762640653615
17
+ >>> volume_of_torus(5, 2)
18
+ 394.7841760435743
19
20
+ if major_radius < 0 or minor_radius < 0:
21
+ raise ValueError("Radii must be non-negative")
22
+ return 2 * (math.pi ** 2) * major_radius * (minor_radius ** 2)
23
24
+if __name__ == "__main__":
25
+ import doctest
26
+ doctest.testmod()
0 commit comments