python - 使用另一个文件中的函数进行计算
问题描述
我正在尝试使用另一个文件中的函数进行计算。我有一个脚本,我想通过使用另一个文件中的函数来计算平均值,我已经收到了特定文本的字数。我想在我当前的脚本中使用这个数字来计算平均值。我尝试使用的功能如下所示:
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 函数中添加 return 语句如下
def Word(liste):
test =(len(liste))
return test
并表示功能修改
result = Sum/Word(liste)
推荐阅读
- javascript - 如何根据索引位置映射数组
- javascript - 如何获取从文本文件中读取的多个变量并将它们放入数组中
- c# - 找不到适合“RestDataService”类型的构造函数
- node.js - 未勾选时无法读取复选框
- xcode - 如何将 CMake Xcode 模式生成器限制为仅某些目标
- html - 图片无法在网页上呈现
- javascript - 使用节点和续集插入到 postgress 数据库时出现无效的错误
- python - 如何将多个字典转换为单个字典
- php - 如何以表单模式引导程序从其他表中传递值
- firebase - Firebase - 在 Windows 中的 Firebase CLI 中设置时出错