TheAlgorithms-Python

Форк
0
/
dodecahedron.py 
73 строки · 2.1 Кб
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()
74

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.