【问题标题】:I have been working here on basic calculator based on a formula in python我一直在这里基于python中的公式研究基本计算器
【发布时间】:2021-09-25 13:25:08
【问题描述】:
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>

【问题讨论】:

  • 试试return f"{ppv} {rcl}"return (ppv, rcl)
  • 它没有帮助,无论如何感谢您的回复

标签: python add


【解决方案1】:

见下文(类似这样):

  • 从用户那里获取输入
  • 调用函数并传递参数
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)))

【讨论】:

  • 很高兴我能帮上忙。你可以接受答案。
  • 你能更正你的格式吗?这对访问者来说并不容易复制和尝试。 (而且你在结尾处有多余的打印)。
  • @quamrana 不确定需要改进的地方 - 您可以尝试修改它。谢谢。
【解决方案2】:

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

print(answers())

代替

print(answers)

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

【讨论】:

  • 这无济于事,我已经知道了一个错误。错误在这里 Traceback(最近一次调用):文件“C:\Users\Padmanaban\PycharmProjects\presicionrecall\main.py”,第 17 行,在 print(answers()) 文件“C:\Users\Padmanaban \PycharmProjects\presicionrecall\main.py",第 3 行,在答案中 ppv = tp/(tp + fp) TypeError: unsupported operand type(s) for /: 'str' and 'str'
  • 啊,为此您需要将 input() 的输出转换为 int 或 float。试试 float(input("Enter the value of XYZ")) 代替。
【解决方案3】:

您的代码中有几个错误。您应该阅读一些 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() 函数中使用。

【讨论】:

    猜你喜欢
    • 2017-09-19
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多