total and utter newbie

John Hunter jdhunter at nitace.bsd.uchicago.edu
Tue Nov 12 18:54:41 EST 2002


>>>>> "rockbox" == rockbox  <rockboxb at webmail.co.za> writes:

    rockbox> Hi.  I hope that this is the right group to post this
    rockbox> problem in. If not then I appologise.

Ahh yes, the oldest newbie problem in the book :-)

In current versions of python (as in C and many other programming
languages) an integer divided by an integer returns an integer, so

x = 3/2      #x is 1

but if either number is a floating point number, then the division you
are expecting is used

x = 3.0/2.0  # x = 1.5

The trick is to add a decimal point and a 0 to your number unless you
want integer behavior

x = 3.0/2  # this is also 1.5

This is being phased out of python, and is slated for destruction.

Recent versions of python (2.2?) allow you to use

from __future__ import division

at the beginning of your program to get the division you are
expecting.

See http://www.python.org/peps/pep-0238.html for the official
information about these changes, and how how to do old fashioned
integer division under the new system when you want to.

Have fun!
John Hunter




More information about the Python-list mailing list