Python 为什么蟒蛇给我热的不是真的热?

Python 为什么蟒蛇给我热的不是真的热?,python,Python,Python选择第一个为true的条件,并跳过其余的if..elif..else分支 120>85为真,因此第一次测试通过,并打印出'Hot'。第二次测试在这一点之后是否匹配并不重要 首先进行>100测试: 或者,限制测试以排除上限范围: if temp > 100: print "REALLY HOT!" elif temp > 85: print "Hot" elif temp > 60: print "Comfortable" else: pri

Python选择第一个为true的条件,并跳过其余的
if..elif..else
分支

120>85
为真,因此第一次测试通过,并打印出
'Hot'
。第二次测试在这一点之后是否匹配并不重要

首先进行
>100
测试:

或者,限制测试以排除上限范围:

if temp > 100:
   print "REALLY HOT!"
elif temp > 85:
   print "Hot"
elif temp > 60:
   print "Comfortable" 
else:
   print "Cold"

因为120大于85。一旦发现真实情况,它就会停止,你应该改变顺序以适应。
if temp > 100:
   print "REALLY HOT!"
elif temp > 85:
   print "Hot"
elif temp > 60:
   print "Comfortable" 
else:
   print "Cold"
if 100 >= temp > 85:
   print "Hot"
elif temp > 100:
   print "REALLY HOT!"
elif temp > 60:
   print "Comfortable" 
else:
   print "Cold"