price_loyal
- a string (even if it contains numbers found with find
) that you are trying to compare with a numeric value (4.75)? For comparison, try
float(price_loyal)
UPDATE (thanks @agf):
With Python v 3.x, you will get the error message you mentioned.
>>> price_loyal = '555.5' >>> price_loyal > 5000.0 Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> price_loyal > 5000.0 TypeError: unorderable types: str() > float() >>>
then
>>> float(price_loyal) > 5000.0 False
The Python version matters in this case, so it's probably worth mentioning which version it works with. Earlier ... with Python v 2.x
Your comparisons will be disabled before converting your string
to float
. For instance.
price_loyal '555.5'
This comparison with string and float gives True
price_loyal > 5000.0 True
This comparison with float and float gives False
, as it should be
float(price_loyal) > 5000.0 False
Other problems may occur, but it seems like one.
source share