使用另一个文件中的函数进行计算



我正试图使用另一个文件中的函数进行计算。我有一个脚本,我想通过使用来自另一个文件的函数来计算平均值,我已经收到了特定文本的字数。我想在当前脚本中使用这个数字来计算平均值。我试图使用的函数如下所示:

def Word(liste):
test =(len(liste))

我尝试添加这个来计算平均值,看起来像这样:

def mean(liste, Word):

Sum = (sum(liste))
result = Sum/Word
print(result)

不幸的是,我总是得到以下错误:

TypeError: unsupported operand type(s) for /: 'float' and 'function'

但是我如何将函数更改为整数呢?这可能吗?

为word function添加如下返回语句

def Word(liste):
test =(len(liste))
return test

表示函数修改

result = Sum/Word(liste)

最新更新