mercredi 18 septembre 2019

Python compares wrong two negative numbers.( Tells me that -266>=-258 )

I am trying to compare two negative numbers, that are two elements of two arrays. So I am using an if statement to provoke an action when one element is smaller (has grater absolute value but is negative) than the other.

The problem is that python compares the numbers wrong.

Example : For two numbers -258 and -266, python tells me that -266>=-258.

>>> print(old2[-1]) 

-266.87698985042744

>>> print(new2[-1])

-258.32825854700866

>>> if old2[-1]<=new2[-1]:
...     print('k')
... 

NO OUTPUT

>>> if old2[-1]>=new2[-1]:
...     print('k')
... 

k

I expect python to print "k" because of the first if statement, old2[-1]<=new2[-1] .

Thank you.

Aucun commentaire:

Enregistrer un commentaire