Performing arithmetic on floating point values of different sizes Performing arithmetic on floating point values of different sizes tkinter tkinter

Performing arithmetic on floating point values of different sizes


I'm guessing that mmin and current and mmax are strings. In which case, this expression:

if mmin <= current <= mmax and 0 <= capacity <= 100:

... Is doing a lexicographical comparison on the values. This is different from a numerical comparison: for example, "5000" < "10000" evaluates to False because "5" is larger than "1".

Convert your values to numbers before doing comparisons on them.

if mmax.isdigit() and mmin.isdigit() and current.isdigit():    mmax = float(mmax)    current = float(current)    mmin = float(mmin)    capacity = float(100 * ... #etc

Or

if float(mmin) <= float(current) <= float(mmax) and 0 <= capacity <= 100: