nil value for multiply

i got asimple equaton and get a value of 0?

genr = 10.0

print ‘genr*(2/3)=’, genr*(2/3),‘genr =’,genr

and this get me genr*(2/3), =0 ?

how can i correct this so it works?

Thanks

Hi,

Looks like you’re using integers in your division. Try

genr = 10.0
print 'genr*(2/3)=', genr*(2/3.0),'genr =',genr

so as soon as you put an expression with integer the rest of the equation is evalutated as integer!

hum ?

Thanks i’ll change it to real number

Hi,

If you present an expression containing only integers, the result will be returned as an integer. If you need greater precision, you should include a higher precision value in the expression (e.g. a float). It seems a bit strange, but there are good reasons for it to work this way.

Although I think I read that for Python 3.0, it does an automatic conversion to float. In older versions there’s:


from __future__ import division

if its really necessary it operate as it would mathematically…

you put that at the beginning of the main i guess

and it will work with the python 2.6 with 2.49a

i hope 2.5 will be with python 3

it might be easier to program that way

now i still have to settled the other problem with Nesh and ob data
but htat’s part of another thread anyway

Thanks guys