【发布时间】:2017-12-16 23:13:32
【问题描述】:
我是 python 编程的新手,我的代码出现运行时错误。任何帮助表示赞赏。
import statistics
tc = int(input())
while tc > 0:
n = int(input())
arr = input()
l = list(map(int, arr.split(' ')))
print("{} {} {}".format(statistics.mean(l), statistics.median(l), statistics.mode(l)))
tc = tc - 1
错误
StatisticsError: no unique mode; found 2 equally common values
输入格式
第一行由一个整数 T 组成,表示测试用例的数量。 每个测试用例的第一行由一个整数 N 组成,表示数组的大小。 以下行由 N 个空格分隔的整数 Ai 组成,表示数组中的元素。
输出格式
对于每个测试用例,输出一行包含三个分隔的整数,表示数组的均值、中位数和众数
示例输入
1
5
1 1 2 3 3
样本输出
2 2 1
【问题讨论】:
-
能否将错误输出添加到您的问题中?
-
StatisticsError: no unique mode; found 2 equally common values -
@cᴏʟᴅsᴘᴇᴇᴅ 谢谢。我将错误编辑到问题中。
-
这不是错误,而是
statistics.mode函数的未来 -
@flevinkelming,我提到过,我收到运行时错误 (ideone.com/QAubql)
标签: python arrays python-3.x statistics