"""File: avg_var.py Purpose: Find the average, variance, and standard deviation of a collection of user input numbers Run: python avg_py.py Input: A sequence of numbers, one per line of input, 0 terminates input Output: The average, variance, and standard deviation of the numbers """ from math import sqrt sum = 0.0 sum_sq = 0.0 count = 0 number = float(raw_input("Enter the first number (0 to quit)\n")) while number != 0: sum = sum + number sum_sq = sum_sq + number*number count = count + 1 number = float(raw_input("Enter the next number (0 to quit)\n")) if count > 0: avg = sum/count print "The average of the input values is", avg else: print "You didn't enter any nonzero numbers!" if count > 1: variance = (sum_sq - count*avg*avg)/(count-1) std_dev = sqrt(variance) print "variance =", variance print "std deviation =", std_dev else: print "For variance you need at least two numbers"