You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python实现的PPV与召回率计算器无报错却无法输出正确结果排查

问题排查与修复方案

核心问题1:函数未正确调用

你代码最后一行写的是print(answers),这里直接输出的是answers这个函数对象本身的内存地址,也就是你看到的<function answers at 0x...>内容。想要执行函数拿到返回的计算结果,必须在函数名后加括号,写为answers()。

核心问题2:输入值未做类型转换

input()函数默认返回的是字符串类型,直接用来做加减乘除的数值运算会抛出类型错误,你需要先把输入的内容转换为整数或者浮点数类型。

优化建议

最好把计算需要的参数通过传参的方式传入函数,不要直接依赖全局变量,避免后续变量命名冲突导致计算结果异常。

修正后的完整代码

def answers(tp, fp, fn):
    ppv = tp/(tp + fp)
    rcl = tp/(tp + fn)
    return ppv, rcl


print("enter the value of true positive")
tp = float(input())
print("enter the value of false negative")
fn = float(input())
print("enter the value of false positive")
fp = float(input())
print("enter the value of true negative")
tn = float(input())
print('ppv and recall answers')
print(answers(tp, fp, fn))

内容的提问来源于stack exchange,提问作者Venkat Sr5

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 02:06:03