Write A Python Program To Find The Variance And Standard Deviation For The Given Data

Hi Programmers, welcome to my blog, lets try to get python solution for write a python program to find the variance and standard deviation for the given data.







Title :

Python Problem : Write A Python Program To Find The Variance And Standard Deviation For The Given Data


Description :

Get the above sample data containing list, get the sum of list of numbers and divide it by length to get mean, Subtract and square all the numbers with mean and find the sum, again divide it by length will get you the variance Then get the square oot of variance will get you standard deviation. Finally print both the variables., Sample Data sample = [130,137,136,142,135]


Code :

import math

sample = [130, 137, 136, 142, 135]
n = len(sample)
mean = sum(sample) / n
variance = sum((x - mean) ** 2 for x in sample) / n
standard_dev = math.sqrt(variance)

print(variance, standard_dev)


Conclusion :

Once you are done with reading the above code, open your python editor, try to write the program by yourself. This will improve your coding skills, try changing variable names, change operators and execute it.

Thank you for reading my article about write a python program to find the variance and standard deviation for the given data if you have any queries about above solution, please comment down below, if you like this article share it with your friends.