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

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

I am still having trouble with this problem

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?

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

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

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.