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 Things Together

Recall from Chapter 4 that we wrote a function called getMean() that figured the average of a set of house prices. Well, we can change it to accept two default arguments. The first argument, sample, is a flag that tells getMean() if the set of numbers passed to it is from a sample of a population or the population as a whole. (The mean and the average of a sample are calculated differently.) The second argument, display, is a flag that tells getMean() to optionally display the results to the monitor.

getMean()

Here's getMean()() defined:

 def getMean (nums, sample=0, display=0): for x in nums: sum = sum + x if(sample): average = sum / (len(nums)-1) else: average = sum / len(nums) if(display): print ("mean = " + 'average') ...

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