[Tutor] attribute error
alan.gauld at btinternet.com
Mon Jul 30 01:56:42 CEST 2007
"Sara Johnson" <sarliz73 at yahoo.com> wrote
> I always thought with floats you needed a 0.0.
> I do have some percentages that are less than 1% but more than 0.0.
If you already have a float value then you can compare it to an int
save the typing. zero means the same in a float comparison as 0.0
If you were trying to do float arithmetic, especially division, you
exress at least one of the values as a float. The code you originally
did that by just having a decimal point at the end - which is terrible
style - but
its more conventional (ie. more readable) to add .0 But
>fracmiss = 1.0 * numberMissing( z[key].values() ) / nsites
In this case mutiplying by 1.0 seems to be a clumsy way to ensure
a float result when
>fracmiss = float(numberMissing( z[key].values() )) / nsites
would achieve the same and be more explicit as to purpose.
More information about the Tutor