June 2002
Beginner to intermediate
640 pages
14h 24m
English
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.
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') ...Read now
Unlock full access