我在下面的代码中编写了断言代码:
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))
当我使用命令提示符运行(Windows 10,Python 3.6.1)上述代码时:断言工作正常。
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!
但是当我使用 sublime O/P 运行时 -
32.0
451
-468.40000000000003
[Finished in 0.3s]
请有人指导我
最佳答案
我尝试过,但得到了与预期相同的断言错误。 您可能正在运行不同的版本。 python shell 和 pythonidle 将处于不同的版本。
关于python - CMD Prompt 和 Sublime Buid 中的不同 OP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45261629/