下面是我的代码,它给我这样的错误 TypeError:+:' int'不支持的操作数类型和' str'
def mean(numbers):
return sum(numbers) / float(len(numbers))
def stdev(numbers):
avg = mean(numbers)
variance = sum([pow(x - avg, 2) for x in numbers]) / float(len(numbers) - 1)
return math.sqrt(variance)
我试着像这样改变它
def mean(numbers):
return sum([int(numbers)]) / float(len(numbers))
def stdev(numbers):
avg = mean(numbers)
variance = sum([pow(x - avg, 2) for x in numbers]) / float(len(numbers) - 1)
return math.sqrt(variance)
但是这次它给了我这个错误 TypeError:int()参数必须是字符串,类字节对象或数字,而不是'元组'
答案 0 :(得分:0)
将您的第一个功能更改为
def mean(numbers):
return sum([int(x) for x in numbers]) / float(len(numbers))