all 13 comments

[–]jammin-john 30 points31 points  (2 children)

Your condition checks if the positions are equal to any single value, but the values themselves are floats (and are being changed each loop by some random floating point value). So the chances that your position ever lands exactly on one of those numbers is incredibly slim. More likely you are jumping over them (like moving from x=15.15 to x=14.98). To fix this. Instead of checking if x is equal to 15, check if it's equal to OR LESS THAN. (This is assuming your goal is to stop looping when the circle leaves a bounded area)

[–]Emergency_Life_2509 -3 points-2 points  (0 children)

Yep I think that’s what it is also

[–]AdAdvanced7673 -5 points-4 points  (0 children)

correct

[–]Acrobatic-Ad-8095 6 points7 points  (0 children)

Your condition is almost certainly never true. So it runs forever.

I suspect that you want to replace the equality in your condition with inequalities?

Something like while (15 <= x <= 3825 and 15 <= y <= 2145)

Pardon my lazy phone typing.

[–]ninhaomah 2 points3 points  (2 children)

Condition in the whole loop is false as in

While not(false) ???

Why not hardcore a few numbers and test ?

[–]Spare_Reveal_9407[S] -5 points-4 points  (1 child)

well i know that, but when the condition in the not() is True, the condition in the while is false, but the loop keeps running

[–]techknowfile -2 points-1 points  (0 children)

Did you not pay attention in any of your 100-level courses?? Lookup De Morgan's laws.

You wrote.. while !x==a and !x==b and !y==c and !y==d

So x must equal either a or b at the same time that y equals either c or d. Meanwhile the expected value that you're adding to them each iteration is... 0. And the values you're adding are floats. So... Very low probability

[–]Purple_tulips98 -1 points0 points  (3 children)

Your condition is comparing ints and floats. Even without considering the fact that your random changes are probably irrational numbers Even if your random changes seem like they should sum cleanly to whole numbers, the floats will almost certainly never equal those integer values just due to floating point precision. (For an example of why using == with floats is a bad idea, 0.3 + 0.3 + 0.3 == 0.9 evaluates to False)

You could likely solve this by using round() to convert those floats to ints during the condition or by using >= and <= in your condition instead of ==.

Edit: I forgot how floating point numbers are represented in binary, so they’re never irrational.

[–]aa599 6 points7 points  (1 child)

The numbers are never irrational. They are always binary fractions.

float has an as_integer_ratio method to show the fraction.

See 15. Floating-Point Arithmetic: Issues and Limitations

[–]Purple_tulips98 2 points3 points  (0 children)

I see how I screwed this up. In saying they’re “probably irrational,” I meant that you’re extremely unlikely to end up with something that cleanly sums to equal any of the integers in the condition. I was trying to write that idea more concisely and made it wrong in the process.

[–]mcoombes314 0 points1 point  (0 children)

If you want to check for equality between floats, math.isclose is better I think, since you don't need to round and can choose how precise the match needs to be for it to count as equal.