pacers10

I think i have the function for mean but i also need to figure out below mean. This what i have so far.

``````import math

def mean(alist):
belowMean = alist

mean = sum(alist) / len(alist)
if mean <= alist:
belowMean = item

return belowMean``````

pyTony 888

item is undefined. If type of mean is float, then alist > mean as 'list' > 'float'

pacers10

I am still having trouble with this problem

Schol-R-LEA 1,087

Hold on here. Getting the mean (or average) is a fairly simple thing in and of itself:

``````import math

def mean(*alist):
return sum(alist) / float(len(alist))``````

What you're doing doesn't seem to be aimed at just getting the mean of a list of values, however. What is `item` for, and just what should this function of yours return?

pacers10

after i find the mean , i need to find the numbers that is under mean

woooee 814

Add some swear words. That will make it mean. Also, add some print statements so you can see what the program is doing. And if you can not complete the problem, try it another way. Perhaps computing the mean by adding each element of the list to a total field, via a for loop. Obviously you do not understand what this code is doing so staring at it will not help; a different method may.

``````def mean(alist):
belowMean = alist

mean = sum(alist) / len(alist)
print "I am mean, GRRRRR", mean
print "comparing for <=", mean, "with", alist
if mean <= alist:
belowMean = item

return belowMean``````

cghtkh 9

This may be what you want, to return a list of items below the mean.

``````def mean(alist):
belowMean = []
mean = sum(alist) / len(alist)
for item in alist:
if item<mean:
belowMean.append(item)

return belowMean``````

pacers10

I keep getting meanBelow not defined

``````import math
def mean(alist):

meanBelow =[]
mean = sum(alist) / len(alist)
for item in  alist:
if item < mean :
meanBelow.append(item)
return   meanBelow``````

Schol-R-LEA 1,087

Odd... the code as given works fine on my system, in both the 2.6 and 3.0 interpreters. What version of Python are you using?

You might want to try using list() instead of [] when initializing meanBelow, as that's a little more explicit, but they both should work the same way in any version of the language I know of.