Skip to content

Commit ded5dea

Browse files
shri30yanscclausspre-commit-ci[bot]ZeroDayOwl
authored
Dodecahedron surface area and volume (TheAlgorithms#6606)
* Hexagonal number sequence A hexagonal number sequence is a sequence of figurate numbers where the nth hexagonal number hₙ is the number of distinct dots in a pattern of dots consisting of the outlines of regular hexagons with sides up to n dots, when the hexagons are overlaid so that they share one vertex. This program returns the hexagonal number sequence of n length. * Update hexagonalnumbers.py * Update hexagonalnumbers.py * Update hexagonalnumbers.py * Update hexagonalnumbers.py * Update and rename hexagonalnumbers.py to hexagonal_numbers.py * Length must be a positive integer * Create dodecahedron.py * Update dodecahedron.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update dodecahedron.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update dodecahedron.py * Update dodecahedron.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update dodecahedron.py * Update dodecahedron.py * Apply suggestions from code review Co-authored-by: Paul <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestions from code review * Update dodecahedron.py Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Paul <[email protected]>
1 parent 506b63f commit ded5dea

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

maths/dodecahedron.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# dodecahedron.py
2+
3+
"""
4+
A regular dodecahedron is a three-dimensional figure made up of
5+
12 pentagon faces having the same equal size.
6+
"""
7+
8+
9+
def dodecahedron_surface_area(edge: float) -> float:
10+
"""
11+
Calculates the surface area of a regular dodecahedron
12+
a = 3 * ((25 + 10 * (5** (1 / 2))) ** (1 / 2 )) * (e**2)
13+
where:
14+
a --> is the area of the dodecahedron
15+
e --> is the length of the edge
16+
reference-->"Dodecahedron" Study.com
17+
<https://study.com/academy/lesson/dodecahedron-volume-surface-area-formulas.html>
18+
19+
:param edge: length of the edge of the dodecahedron
20+
:type edge: float
21+
:return: the surface area of the dodecahedron as a float
22+
23+
24+
Tests:
25+
>>> dodecahedron_surface_area(5)
26+
516.1432201766901
27+
>>> dodecahedron_surface_area(10)
28+
2064.5728807067603
29+
>>> dodecahedron_surface_area(-1)
30+
Traceback (most recent call last):
31+
...
32+
ValueError: Length must be a positive.
33+
"""
34+
35+
if edge <= 0 or not isinstance(edge, int):
36+
raise ValueError("Length must be a positive.")
37+
return 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2)
38+
39+
40+
def dodecahedron_volume(edge: float) -> float:
41+
"""
42+
Calculates the volume of a regular dodecahedron
43+
v = ((15 + (7 * (5** (1 / 2)))) / 4) * (e**3)
44+
where:
45+
v --> is the volume of the dodecahedron
46+
e --> is the length of the edge
47+
reference-->"Dodecahedron" Study.com
48+
<https://study.com/academy/lesson/dodecahedron-volume-surface-area-formulas.html>
49+
50+
:param edge: length of the edge of the dodecahedron
51+
:type edge: float
52+
:return: the volume of the dodecahedron as a float
53+
54+
Tests:
55+
>>> dodecahedron_volume(5)
56+
957.8898700780791
57+
>>> dodecahedron_volume(10)
58+
7663.118960624633
59+
>>> dodecahedron_volume(-1)
60+
Traceback (most recent call last):
61+
...
62+
ValueError: Length must be a positive.
63+
"""
64+
65+
if edge <= 0 or not isinstance(edge, int):
66+
raise ValueError("Length must be a positive.")
67+
return ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3)
68+
69+
70+
if __name__ == "__main__":
71+
import doctest
72+
73+
doctest.testmod()

0 commit comments

Comments
 (0)