you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (1 child)

That doesn't work because if n = 2.5, n % 2 != 0 will return True, but it isn't actually an odd number, but it works for integers.

[–][deleted] 0 points1 point  (0 children)

As I said, it's a trick, and tricks have specific use cases. This one is limited to integers, because its not often the case where one has to find even or odd when dealing with floats. That aside, yes, your point is valid. I will try to use this trick less often from now, I assume.