用python给出一组数,求总个数、求和、平均值、中位数、方差…
时间: 2024-01-26 08:03:27 浏览: 140
求值_python_方差_中位数_平均值_
5星 · 资源好评率100%
以下是一组数据的例子:
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
求总个数:
count = len(data)
print("总个数:", count)
求和:
total = sum(data)
print("总和:", total)
求平均值:
average = total / count
print("平均值:", average)
求中位数:
if count % 2 == 0:
median = (data[int(count/2)-1] + data[int(count/2)]) / 2
else:
median = data[int(count/2)]
print("中位数:", median)
求方差:
variance = sum([(x-average)**2 for x in data]) / count
print("方差:", variance)
阅读全文