File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments