How to add conditionals to sliders using python?


(Dilushanr) #1

I was using this slider guard that always give me 3 outputs sums up to 1, but this error shows up for some marginal values of the sliders.

slider guard to sum up (4.8 KB)

I’m stuck at the final simulation process of my thesis because of this error, much appreciated if someone could fix this for me.


(David Rutten) #2

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.