<reponame>Vemestael/stepik<filename>stepik/dispersion.py
from math import sqrt
from central_tendency import mean


def range(dataset: list):
    dataset.sort()
    return dataset[-1] - dataset[0]


def variance(dataset):
    mean_value = mean(dataset)
    avg_deviation = 0
    for el in dataset:
        avg_deviation += (el - mean_value) ** 2
    return avg_deviation / (len(dataset) - 1)


def standard_deviation(dataset):
    variance_value = variance(dataset)
    return sqrt(variance_value)


def main():
    dataset = [329, 92, 253, 97, 52, 243, 296, 250, 415, 498, 472, 182, 16, 229, 255,
               496, 443, 320, 262, 297, 275, 4, 198, 166, 166, 164, 196, 191, 30, 287,
               208, 402, 354, 417, 338, 220, 62, 457, 128, 53, 32, 128, 436, 484, 114,
               253, 313, 309, 287, 40, 252, 114, 347, 148, 278, 378, 384, 14, 17, 296,
               227, 207, 379, 110, 337, 70, 342, 170, 412, 294, 57, 217, 228, 454, 53,
               80, 282, 364, 168, 252, 184, 306, 309, 86, 211, 445, 177, 464, 248, 22,
               149, 7, 162, 61, 237, 30, 490, 13, 417, 141]
    print(standard_deviation(dataset))


if __name__ == "__main__":
    main()

from math import sqrt
from central_tendency import mean


def range(dataset: list):
    dataset.sort()
    return dataset[-1] - dataset[0]


def variance(dataset):
    mean_value = mean(dataset)
    avg_deviation = 0
    for el in dataset:
        avg_deviation += (el - mean_value) ** 2
    return avg_deviation / (len(dataset) - 1)


def standard_deviation(dataset):
    variance_value = variance(dataset)
    return sqrt(variance_value)


def main():
    dataset = [329, 92, 253, 97, 52, 243, 296, 250, 415, 498, 472, 182, 16, 229, 255,
               496, 443, 320, 262, 297, 275, 4, 198, 166, 166, 164, 196, 191, 30, 287,
               208, 402, 354, 417, 338, 220, 62, 457, 128, 53, 32, 128, 436, 484, 114,
               253, 313, 309, 287, 40, 252, 114, 347, 148, 278, 378, 384, 14, 17, 296,
               227, 207, 379, 110, 337, 70, 342, 170, 412, 294, 57, 217, 228, 454, 53,
               80, 282, 364, 168, 252, 184, 306, 309, 86, 211, 445, 177, 464, 248, 22,
               149, 7, 162, 61, 237, 30, 490, 13, 417, 141]
    print(standard_deviation(dataset))


if __name__ == "__main__":
    main()