Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions maths/volume_of_torus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
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)

Check failure on line 13 in maths/volume_of_torus.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

maths/volume_of_torus.py:13:89: E501 Line too long (92 > 88)
: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()
Loading