命令提示符和升华构建中的不同操作

2024-09-29 17:51:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经编写了一个代码,在下面的代码中声明:

def KelvinToFahrenheit(Temperature):
    assert (Temperature >= 0),"Colder than absolute zero!"
    return ((Temperature-273)*1.8)+32

print (KelvinToFahrenheit(273))
print (int(KelvinToFahrenheit(505.78)))
print (KelvinToFahrenheit(-5))

当我运行(windows10,python3.6.1)时,使用命令提示符:assertion的上述代码工作正常

O/P :
32.0
451

Traceback (most recent call last):
File "assert.py", line 8, in <module>
print (KelvinToFahrenheit(-5))
File "assert.py", line 2, in KelvinToFahrenheit
assert (Temperature >= 0),"Colder than absolute zero!"
AssertionError: Colder than absolute zero!

但当我用升华O/p跑的时候-

32.0 
451
-468.40000000000003
[Finished in 0.3s] 

有人给我引路吗


Tags: 代码inpy声明deflineassertfile
2条回答

看来你用的是魅力而不是崇高。我从未使用过PyCharm,但您的问题应该是,您运行的“PycharmProjects/ppp/loop.py”项目的配置打开了PYTHONOPTIMIZE环境变量。此模式将任何assert语句转换为空操作,并且不会对其求值

您应该检查IDE中的运行/调试配置

我试过了,我得到了与预期相同的断言错误。 您可能正在运行另一个版本。 pythonshell和pythonidle的版本不同

相关问题 更多 >

    热门问题