[Tutor] If elif not working in comparison

Sean Perry shaleh at speakeasy.net
Tue Mar 29 10:48:38 CEST 2005


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?


More information about the Tutor mailing list