Not a python expert, but if you are comparing floating point values you *must* add tolerances to your code.

Floating point values cannot represent certain values that we can type in decimal exactly. For example 0.1 can be written using only three symbols in base-10, but it becomes the infinite string 0.00011001100110011001100... in binary. Since you’re only allowed 64 bits per number, you get an approximation of the *real* one-tenth.

It’s okay to use the equals operator for integers, but when you’re comparing floats (*especially* if they are the result of some mathematical operations), then you must always compare them to within some tolerance, for example; abs(a - b) < 10^{-12}. What tolerance you pick depends on the specific case you’re dealing with and can be far from a straightforward choice.