Putting It All Together

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()

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 ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.