O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required