data collections def mean(nums)sum for num in numssum sum num return sum len(numsnotice how the average is computed and returned in the last line of this function the len operation returns the length of listwe don' need separate loop accumulator to determine how many numbers there are with these two functionsour original program to average series of numbers can now be done in two simple linesdef main()data getnumbers(print('the mean is'mean(data)nextlet' tackle the standard deviation functionstddev in order use the standard deviation formula discussed abovewe first need to compute the mean we have design choice here the value of the mean can either be calculated inside of stddev or passed to the function as parameter which way should we do iton the one handcalculating the mean inside of stddev seems cleaneras it makes the interface to the function simpler to get the standard deviation of set of numberswe just call stddev and pass it the list of numbers this is exactly analogous to how mean (and median belowworks on the other handprograms that need to compute the standard deviation will almost certainly need to compute the mean as well computing it again inside of stddev results in the calculations being done twice if our data set is largethis seems inefficient since our program is going to output both the mean and the standard deviationlet' have the main program compute the mean and pass it as parameter to stddev other options are explored in the exercises at the end of the here is the code to compute the standard deviation using the mean (xbaras parameterdef stddev(numsxbar)sumdevsq for num in numsdev xbar num sumdevsq sumdevsq dev dev return sqrt(sumdevsq/(len(nums)- )notice how the summation from the standard deviation formula is computed using loop with an accumulator the variable sumdevsq stores the running sum of the squares of the deviations once this sum has been computedthe last line of the function calculates the rest of the formula finallywe come to the median function this one is little bit trickieras we do not have formula to calculate the median we need an algorithm that picks out the middle value the first step is to arrange the numbers in increasing order whatever value ends up in the middle of the