Computes the standard deviation of numbers This exercise use
Computes the standard deviation of numbers. This exercise uses a different but equivalent formula to compute the standard deviation of n numbers. mean = sigma_i = 1^n x_i/n = x_1 + x_2 + ... + x_n/n deviation = Squareroot sigma_i = 1^n (x_i - mean)^2/n - 1 To compute the standard deviation with this formula, you have to store the individual numbers using a list, so that they can be used after the mean is obtained. Your program should contain the following functions: Compute the standard deviation of values def deviation(x): Compute the mean of a list of values def mean(x): Write a test program that prompts the user to enter a list of numbers and displays the mean and standard deviation, as shown in the following sample run:
Solution
# Compute the standard deviation of values def deviation(x): sum = 0 for i in range(len(x)): sum += ((x[i]) - mean(x)) ** 2 return (sum / (len(x) - 1)) ** 0.5 # Compute the mean of a list of values def mean(x): sum = 0 for i in range(len(x)): sum += (x[i]) # sum = (x[i]) + sum return sum / len(x) def main(): nums = input(\"Enter numbers: \") x = nums.split() for i in range(len(x)): x[i] = float(x[i]) print (\"The mean is\", mean(x)) print (\"The standard deviation is\", deviation(x)) main()