在 Python 中编写变量添加和自定义结果

Writing variable additions and custom outcomes in Python

我正在尝试创建并 运行 一个允许用户插入 2 个药物名称并接收其结果的程序。这是我的代码到目前为止的样子,但我无法找出语法错误或者这是否是执行我的计划的最佳方式

a = int(input("A.C"))
B = int(input("Opioid"))
sum = a + b
print("Incompatible, increased death rate", sum)

在您的代码中,您对 B 进行了赋值,然后尝试从 b 读取数据。这是两个不同的变量。 Python 中的所有名称都区分大小写。

您需要更改变量名称(b),我还在用户想要输入值时添加了新行。我使用 fprint 打印输出。

a = int(input("A.C \n") )
b = int(input("Opioid \n"))
sum = a+b
print(f'Incompatible, increased death rate, {sum}')