我一直在这里研究基于 python 中的公式的基本计算器

I have been working here on basic calculator based on a formula in python

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


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

这是一个基于 python 中公式的基本计算器,它没有显示任何错误,但也显示了所需的输出,请查看下图了解更多信息

here check the output it returns something like this <function answers at 0x000002377567F040>

您正在打印函数而不是调用它。

print(answers())

而不是

print(answers)

将参数传递给函数而不是全局设置和访问它们也更简洁。

见下文(类似这样的内容):

  • 获取用户的输入
  • 调用函数并传递参数
def answers(tp, fp, fn):
     ppv = tp / (tp + fp)
     rcl = tp / (tp + fn)
     return ppv, rcl
    
    
print("enter the value of true positive")
_tp = input()
print("enter the value of false negative")
_fn = input()
print("enter the value of false positive")
_fp = input()

print('ppv and recall answers')
print(answers(int(_tp), int(_fp), int(_fn)))

您的代码中有几个错误。您应该学习 python 中的一些基本教程,其中应该展示如何调用函数和处理用户输入。

您不调用函数,您应该将输入转换为 ints:

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


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

也许更好的版本是将您的数字转换为 floats 并将它们作为参数传递:

def answers(tp, fn, fp):
    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, fn, fp))

请注意,我已注释掉要求 tn 的位,因为它未在 answers() 函数中使用。