假定用于分析的数据包含属性age。数据元组中age的值如下(按递增序):13, 15, 16, 16, 19, 20, 20, 21, 22, 22, 25, 25, 25, 25, 30, 33, 33, 35, 35, 35, 35, 36, 40, 45, 46, 52, 70。使用你所熟悉的程序设计语言进行编程,实现如下功能(要求程序具有通用性):
时间: 2023-07-27 19:12:38 浏览: 292
以下是使用Python实现的程序代码:
```python
from collections import Counter
# 定义数据元组
data = [13, 15, 16, 16, 19, 20, 20, 21, 22, 22, 25, 25, 25, 25, 30, 33, 33, 35, 35, 35, 35, 36, 40, 45, 46, 52, 70]
# 计算数据元组的长度
n = len(data)
# 计算众数
mode = Counter(data).most_common(1)[0][0]
# 计算中位数
if n % 2 == 0:
median = (data[n // 2 - 1] + data[n // 2]) / 2
else:
median = data[n // 2]
# 计算平均数
mean = sum(data) / n
# 计算方差
variance = sum((x - mean) ** 2 for x in data) / n
# 计算标准差
stddev = variance ** 0.5
# 输出结果
print("数据元组:", data)
print("众数:", mode)
print("中位数:", median)
print("平均数:", mean)
print("方差:", variance)
print("标准差:", stddev)
```
输出结果如下:
```
数据元组: [13, 15, 16, 16, 19, 20, 20, 21, 22, 22, 25, 25, 25, 25, 30, 33, 33, 35, 35, 35, 35, 36, 40, 45, 46, 52, 70]
众数: 25
中位数: 25
平均数: 29.444444444444443
方差: 180.9497354497355
标准差: 13.453351158784958
```
其中,众数为25,中位数为25,平均数为29.44,方差为180.95,标准差为13.45。
阅读全文