Program not entering if statement

后端 未结 7 1843
走了就别回头了
走了就别回头了 2021-01-19 05:01

In my python program, an if statement is not being entered. I have simplified the code to the following:

x = -5
while x < 5:
    if (x == 0):
        prin         


        
7条回答
  •  臣服心动
    2021-01-19 05:30

    Floating point number representation might not be accurate enough. You should never test for zero equality but instead use something along

    if (abs(x) < 1E-10) ...
    

提交回复
热议问题