[Tutor] If elif not working in comparison
Brian van den Broek
bvande at po-box.mcgill.ca
Tue Mar 29 11:22:19 CEST 2005
Sean Perry said unto the world upon 2005-03-29 03:48:
> Kent Johnson wrote:
>
>>> Not without using round. Have *NO* faith in floating points. This is
>>> especially true when you are creating the decimals via division and
>>> the like.
>>
>>
>>
>> What?!?!
>>
>> OK, floats don't necessarily have the exact values you expect (they
>> may have errors after many decimal places), and comparing floats for
>> equality is risky business (you should compare for close, not equal).
>> But the errors are well past the two-digit place. See the FAQ for more
>> info on one kind of error:
>> http://www.python.org/doc/faq/general.html#why-are-floating-point-calculations-so-inaccurate
>>
>>
>> Note that the original poster was looking at ranges, not looking for
>> exact matches!
>>
>> Can you be more specific about what kinds of problems you have had?
>>
>
> sure, what is 2/3? 0.66? 0.67?
>>> 2/3
0
>>> 2.0/3
0.66666666666666663
>>>
More information about the Tutor
mailing list