Python2.7定义一个支持函数来计算平均值

Python2.7定义一个支持函数来计算平均值,python,python-2.7,Python,Python 2.7,我试图定义一个支持函数getMean(alist)来计算将从另一个函数getStats(city\u populations)打印出来的平均值 我的代码: def getMean(alist): alist = sum(city_population,0.0)/len(city_population) def getStats(city_populations): city_populations.sort(key=int) print "The population

我试图定义一个支持函数
getMean(alist)
来计算将从另一个函数
getStats(city\u populations)
打印出来的平均值

我的代码:

def getMean(alist):
    alist = sum(city_population,0.0)/len(city_population)


def getStats(city_populations):
    city_populations.sort(key=int)
    print "The population data in asecending order is:", city_populations
    city_populations.sort(reverse=True)
    print "The population data in descending order is:", city_populations
    print "The max value of the population data is", max(city_populations)
    print "The min value of the populatioon data is", min(city_populations)
    average = getMean(alist)
    print "The mean of the collected data is",average
错误:

NameError:未定义名称“alist”


如何启用
getStats
来使用
getMean
中的值?

如果您已经解决了问题,请选择一个答案或删除您的问题我正在尝试接受您的答案,但我不断收到一个错误,说几分钟后我可以接受
# You passed in the wrong variable
average = getMean(city_population)

# The variable you passed is now called 'alist'
# And by returning the average, your function getStats now has access to it
def getmean(alist):
    return sum(alist,0.0)/len(alist)