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
任何帮助或对错误的认可都将受到广泛赞赏。