MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / vol_icosahedron

Function vol_icosahedron

maths/volume.py:513–540  ·  view source on GitHub ↗

| Calculate the Volume of an Icosahedron. | Wikipedia reference: https://en.wikipedia.org/wiki/Regular_icosahedron >>> from math import isclose >>> isclose(vol_icosahedron(2.5), 34.088984228514256) True >>> isclose(vol_icosahedron(10), 2181.694990624912374) True >>>

(tri_side: float)

Source from the content-addressed store, hash-verified

511
512
513def vol_icosahedron(tri_side: float) -> float:
514 """
515 | Calculate the Volume of an Icosahedron.
516 | Wikipedia reference: https://en.wikipedia.org/wiki/Regular_icosahedron
517
518 >>> from math import isclose
519 >>> isclose(vol_icosahedron(2.5), 34.088984228514256)
520 True
521 >>> isclose(vol_icosahedron(10), 2181.694990624912374)
522 True
523 >>> isclose(vol_icosahedron(5), 272.711873828114047)
524 True
525 >>> isclose(vol_icosahedron(3.49), 92.740688412033628)
526 True
527 >>> vol_icosahedron(0)
528 0.0
529 >>> vol_icosahedron(-1)
530 Traceback (most recent call last):
531 ...
532 ValueError: vol_icosahedron() only accepts non-negative values
533 >>> vol_icosahedron(-0.2)
534 Traceback (most recent call last):
535 ...
536 ValueError: vol_icosahedron() only accepts non-negative values
537 """
538 if tri_side < 0:
539 raise ValueError("vol_icosahedron() only accepts non-negative values")
540 return tri_side**3 * (3 + 5**0.5) * 5 / 12
541
542
543def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected