Image of code

我正在尝试创建一个cal_average函数,请参见下面的代码块:

def cal_average(numbers):
       sum(list_name) = sum(numbers)
       len(list_name) = len(numbers)
       ave(list_name) = sum(list_name)/len(list_names)
       return ave(list_name)


enter code here结果= cal_average([3,4,5])

最佳答案

错误很明显,您不能分配给函数调用,在python中sum是内置函数,len是内置函数,可以使用statistics.mean

import statistics

statistics.mean([3, 4, 5])


输出:

4


或者,如果您想保留功能:

def cal_average(numbers):
       return sum(numbers) / len(numbers)

关于python - 我正在尝试创建一个cal_average函数,但我不断收到python无法分配给函数调用的语法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60245344/

10-14 18:18
查看更多