[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Python comparing float



Hi, this is more a question about python than pygame. Considering this code:

#####################################################
rate = 1
desired_rate = 2

while True:
    if rate != desired_rate:
        print rate, desired_rate, (rate != desired_rate)
        rate += 0.1 * (1 if desired_rate > rate else -1)
    # if
# while
#####################################################

It should smoothly move rate from 1 until 2.
But the output is this:

1 2 True
1.1 2 True
1.2 2 True
1.3 2 True
1.4 2 True
1.5 2 True
1.6 2 True
1.7 2 True
1.8 2 True
1.9 2 True
2.0 2 True
1.9 2 True
2.0 2 True
1.9 2 True
2.0 2 True
1.9 2 True
2.0 2 True
1.9 2 True
2.0 2 True
...

Is python missing in comparison?

--
Ricardo Franco Andrade             @ricardokrieg

( Game | Desktop | Web ) Developer

email: ricardo.krieg@xxxxxxxxx
contact: +55 (86) 9958 9725
             +55 (86) 9436 0830 
twitter: twitter.com/ricardokrieg
facebooK: https://www.facebook.com/krieg.ricardo
github: https://github.com/ricardokrieg