Passed
Push — master ( 9597b9...cc10e5 )
by Ken M.
01:03
created

humpty_dumpty.checkio()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
from math import asin, atanh, pi, sqrt
2
3
4
def volume(height, width):
5
    a = width / 2.0
6
    c = height / 2.0
7
    return round(pi * 4.0 / 3 * a * a * c, 2)
8
9
10
def surface_area(height, width):
11
    a = width / 2.0
12
    c = height / 2.0
13
    if c == a:
14
        return round(4 * pi * a * a, 2)
15
    if c < a:
16
        e2 = 1 - c * c / a / a
17
        return round(2 * pi * a * a * (1 + (1 - e2) / sqrt(e2) * atanh(sqrt(e2))), 2)
18
    else:
19
        e2 = 1 - a * a / c / c
20
        return round(2 * pi * a * a * (1 + c / a / sqrt(e2) * asin(sqrt(e2))), 2)
21
22
23
def checkio(height, width):
24
    return [volume(height, width), surface_area(height, width)]
25
26
27
# These "asserts" using only for self-checking and not necessary for
28
# auto-testing
29
if __name__ == '__main__':
30
    assert checkio(4, 2) == [8.38, 21.48], "Prolate spheroid"
31
    assert checkio(2, 2) == [4.19, 12.57], "Sphere"
32
    assert checkio(2, 4) == [16.76, 34.69], "Oblate spheroid"
33