Now it's time to create a program that uses everything we've learned so far. This program will generate a list of house prices and find their average (mean, mode, and median) and range. The following sections will describe each function in turn.
getRange() iterates through a set of numbers passed to it and calculates the minimum and maximum values. It then returns these values and their range in a tuple.
def getRange (nums): min = 300000000 max = -300000000 for item in nums: if (item > max): max = item if (item < min): min = item return (min, max, max-min)
First getRange() declares two variables, min and max. The min variable refers to a very large number, so the first item extracted from the list is less ...