Skip to content
DeepForgeby svx
All problems
EasyStatisticsst-020

Coefficient of Variation

Problem

Return the coefficient of variation: the sample standard deviation divided by the absolute value of the mean. Return 0.0 when n < 2 or the mean is zero.

Hint

Compute the sample standard deviation, then divide by abs(mean).

Test cases

case 1
in: [[2,4,4,4,5,5,7,9]]
expected: 0.427617987059879
case 2
in: [[10,20,30]]
expected: 0.5
case 3
in: [[5,5,5]]
expected: 0
case 4
in: [[-2,-4]]
expected: 0.47140452079103173
case 5
in: [[0,0]]
expected: 0
Starter codePython
def coefficient_of_variation(data):
    # Your code here
    pass

5 test cases · run your code against them in the editor