if statement - unable to predict result to an if else condition in python -
what following code produce output?
temp = '32' if temp > 85: print "hot" elif temp > 62: print "comfortable" else: print "cold"
you're comparing strings integers. python strongly-typed language: not automatically convert types reason.
>>> 1e320 > '0' false
you should force type conversion if know values bot of same type.
>>> 1e320 > int('0') true
however, if defining value there, please define in way makes comparison valid.
temp = 32 # not '32' if temp > 85: print "hot" elif temp > 62: print "comfortable" else: print "cold"
Comments
Post a Comment