Python不正确的布尔评估

时间:2017-01-13 21:27:31

标签: python boolean

Python似乎不希望在此循环中返回正确的答案。我认为在评估t = 1.8之后代码应该停止,因为t的下一个值2.0,等于b,不小于。

a=0.0
b=2.0
h=0.2
t=a
print "t = ",t
while t<b:
    t+=h;
    print "t = ",t;

输出

t =  0.0
t =  0.2
t =  0.4
t =  0.6
t =  0.8
t =  1.0
t =  1.2
t =  1.4
t =  1.6
t =  1.8
t =  2.0
t =  2.2

任何帮助或对错误的认可都将受到广泛赞赏。

0 个答案:

没有答案