问题遇到的现象和发生背景
一个函数cacluate, 可以接收任意多个参数,返回的是一个元组.元组的第一个值为所有参数的平均值, 第二个值是大于平均值的所有数.
用代码块功能插入代码,请勿粘贴截图
def cacluate(*x):
ave=sum(x)/len(x)
list1=[ave]
list2=[i for i in x if x>ave]
list3=list1+list2
tuple1=tuple(list3)
return tuple1
cacluate(1,2,3,4,5)
运行结果及报错内容
Traceback (most recent call last):
File "E:/Users/**/Documents/Python/cacluate.py", line 9, in <module>
cacluate(1,2,3,4,5)
File "E:/Users/**/Documents/Python/cacluate.py", line 4, in cacluate
list2=[i for i in x if x>ave]
File "E:/Users/**/Documents/Python/cacluate.py", line 4, in <listcomp>
list2=[i for i in x if x>ave]
TypeError: '>' not supported between instances of 'tuple' and 'float'