急求 急求 python语言问题 在线等 马上要交作业 标题要长~~~~~~~~~~~~~

[复制链接]
查看11 | 回复3 | 2011-3-16 04:32:05 | 显示全部楼层 |阅读模式
This assignment is about creating subroutines that compute simple statistics on numeric lists, and testing them in a separate program. In the file as-174-3.zip, you can find 2 files: ListStats.py and ListStatTests.py.
Your task is to complete the implementation the following functions in ListStats.py:
Average(sample)
Average( [a1, ..., an] ) returns the average value of the given list of numeric values.
Median(sample)
Median( [a1, ..., an] ) returns the median value of the given list of numeric values; the median is the numeric value m that has the property that half of the values in sample are smaller than m, and half of the values in sample are larger than m.
Variance(sample)
Variance( [a1, ..., an] ) returns the sample variance of the given list of numeric values; the variance is the mean of the squared differences between the values and the mean of the list of values.

回复

使用道具 举报

千问 | 2011-3-16 04:32:05 | 显示全部楼层
def average(lst):
total = float(sum(lst))
num = len(lst)
return total/numdef median(lst):
n = len(lst)
if n%2 == 1:
lst.sort()
x = lst[(n+1)/2]
return n
else:
x = lst[n/2]
return xdef variance(lst):
mean = average(lst)
n = len(lst)

回复

使用道具 举报

千问 | 2011-3-16 04:32:05 | 显示全部楼层
def average(lst):
total = float(sum(lst))
num = len(lst)
return total/numdef median(lst):
n = len(lst)
if n%2 == 1:
lst.sort()
x = ls
回复

使用道具 举报

千问 | 2011-3-16 04:32:05 | 显示全部楼层
dfsvdf
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行