exercises01   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 42
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Functions

Rating   Name   Duplication   Size   Complexity  
A mean() 0 9 2
A stddev() 0 6 1
A variance() 0 15 2
1
#!/usr/bin/env python3
2 1
"""
3
Matmod exercise 01
4
5
ported to python by https://github.com/SpaceLenore
6
"""
7 1
import math
8
9 1
def mean(numbers):
10
    """
11
    Calculate the mean of an array of numbers
12
    """
13 1
    sumOfNumbers = 0
14 1
    for number in numbers:
15 1
        sumOfNumbers += number
16 1
    res = sumOfNumbers / len(numbers)
17 1
    return round(res, 2)
18
19 1
def variance(numbers):
20
    """
21
    Calculate the sample variance of an array of numbers
22
    """
23 1
    xMean = mean(numbers)
24 1
    totalSum = 0
25
26 1
    for x in numbers:
27 1
        tmp = (x - xMean)**2
28 1
        totalSum += tmp
29
30 1
    final = totalSum / (len(numbers) - 1)
31
32
33 1
    return round(final, 2)
34
35
36 1
def stddev(numbers):
37
    """
38
    Calculate the sample standard deviation of an array of numbers
39
    """
40
41
    return round(math.sqrt(variance(numbers)), 2)
42