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

Python计算器程序输出频繁出现None问题求助

问题修复方案

问题根源

你代码里的input(print("Enter the first value "))写法错误。print()函数执行后返回的是None,当你把它作为input()的参数时,input()会把这个None当作提示文本输出,这就是你看到多余None的原因。input()本身支持直接传入提示字符串,不需要嵌套print()。

修复后的代码

num1 = float(input("Enter the first value "))
num2 = float(input("Enter the second value "))
operator = input("Enter the operator you want to calculate with;+,-,* ")
sum_result = num1 + num2
product = num1 * num2
difference = num1 - num2
if operator == "+":
    print(sum_result)
elif operator == "*":
    print(product)
else:
    print(difference)

注:这里把变量名sum改成了sum_result,因为sum是Python内置函数,用它当变量名可能会引发后续问题。

修复后输出示例

Enter the first value 1
Enter the second value 2
Enter the operator you want to calculate with;+,-,* +
3.0

内容的提问来源于stack exchange,提问作者Syed Shah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 00:01:03