use python as a calculator

Discussion in 'Python' started by ilovesss2004, Jun 24, 2010.

  1. ilovesss2004

    ilovesss2004 Guest

    If I run
    1.0/10**10
    python will return 0

    How can I make python return 1e-10?
     
    ilovesss2004, Jun 24, 2010
    #1
    1. Advertising

  2. On 06/24/2010 05:42 PM, ilovesss2004 wrote:
    > If I run
    > 1.0/10**10
    > python will return 0
    >
    > How can I make python return 1e-10?


    It returns 1e-10.
     
    Thomas Jollans, Jun 24, 2010
    #2
    1. Advertising

  3. ilovesss2004

    Tim Harig Guest

    On 2010-06-24, ilovesss2004 <> wrote:
    > If I run
    > 1.0/10**10
    > python will return 0


    Python 2.6.4 (r264:75706, Dec 11 2009, 23:02:59)
    [GCC 3.4.6] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1.0/10**10

    1e-10
    >>>


    What version are you using?

    > How can I make python return 1e-10?


    If necessary, cast everything to a float:

    >>> 1.0/float(10**10)

    1e-10
    >>>
     
    Tim Harig, Jun 24, 2010
    #3
  4. On Thu, 24 Jun 2010 08:42:32 -0700 (PDT)
    ilovesss2004 <> wrote:
    > If I run
    > 1.0/10**10
    > python will return 0
    >
    > How can I make python return 1e-10?


    What version of Python are you using?

    Python 2.6.4 (r264:75706, Jan 28 2010, 11:26:00)
    [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1.0/10**10

    1e-10

    --
    D'Arcy J.M. Cain <> | Democracy is three wolves
    http://www.druid.net/darcy/ | and a sheep voting on
    +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
     
    D'Arcy J.M. Cain, Jun 24, 2010
    #4
  5. ilovesss2004

    ilovesss2004 Guest

    On Jun 24, 5:50 pm, Tim Harig <> wrote:
    > On 2010-06-24, ilovesss2004 <> wrote:
    >
    > > If I run
    > > 1.0/10**10
    > > python will return 0

    >
    > Python 2.6.4 (r264:75706, Dec 11 2009, 23:02:59)
    > [GCC 3.4.6] on linux2
    > Type "help", "copyright", "credits" or "license" for more information.
    >
    > >>> 1.0/10**10

    > 1e-10
    >
    > What version are you using?
    >
    > > How can I make python return 1e-10?

    >
    > If necessary, cast everything to a float:
    >
    >
    >
    >
    >
    > >>> 1.0/float(10**10)

    > 1e-10


    I use python 2.5
    Must change version? Is there any other solution?
     
    ilovesss2004, Jun 24, 2010
    #5
  6. ilovesss2004

    Tim Wintle Guest

    On Thu, 2010-06-24 at 09:33 -0700, ilovesss2004 wrote:
    > On Jun 24, 5:50 pm, Tim Harig <> wrote:
    > > On 2010-06-24, ilovesss2004 <> wrote:
    > >
    > > > If I run
    > > > 1.0/10**10
    > > > python will return 0

    > >
    > > Python 2.6.4 (r264:75706, Dec 11 2009, 23:02:59)
    > > [GCC 3.4.6] on linux2
    > > Type "help", "copyright", "credits" or "license" for more information.
    > >
    > > >>> 1.0/10**10

    > > 1e-10
    > >
    > > What version are you using?
    > >
    > > > How can I make python return 1e-10?

    > >
    > > If necessary, cast everything to a float:
    > >
    > >
    > >
    > >
    > >
    > > >>> 1.0/float(10**10)

    > > 1e-10

    >
    > I use python 2.5
    > Must change version? Is there any other solution?


    Are you sure you're doing the above?

    Testing on 2.5:

    >>> 1.0/10**10

    1e-10

    .... but if you leave off the ".0" it'll think you want integer
    arithmatic, so return 0.

    >>> 1/10**10

    0

    Tim
     
    Tim Wintle, Jun 24, 2010
    #6
  7. Le 24/06/2010 18:33, ilovesss2004 a écrit :

    > I use python 2.5
    > Must change version? Is there any other solution?


    With python 2.6.5, I obtain 1e-10.

    --

    Etienne
     
    Etienne Rousee, Jun 24, 2010
    #7
  8. ilovesss2004

    Peter Otten Guest

    ilovesss2004 wrote:

    > If I run
    > 1.0/10**10
    > python will return 0
    >
    > How can I make python return 1e-10?


    If you meant 1/10**10, by default this returns an integer in Python 2.x.
    With "from __future__ import division" you can opt for the division of
    integers to return a float:

    >>> 1/10**10

    0
    >>> from __future__ import division
    >>> 1/10**10

    1e-10

    Python 3.x will return a float by default.

    Peter
     
    Peter Otten, Jun 24, 2010
    #8
  9. ilovesss2004

    Ian Kelly Guest

    On Thu, Jun 24, 2010 at 10:33 AM, ilovesss2004 <> wrote:
    > I use python 2.5
    > Must change version? Is there any other solution?


    It works for me:

    Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on
    win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1.0/10**10

    1e-010

    Perhaps you're doing integer division by mistake?

    >>> 1/10**10

    0L

    Cheers,
    Ian
     
    Ian Kelly, Jun 24, 2010
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gerson Kurz
    Replies:
    0
    Views:
    379
    Gerson Kurz
    Dec 4, 2003
  2. Raymond L. Buvel

    ANN: rpncalc-1.0 RPN Calculator For Python

    Raymond L. Buvel, Nov 28, 2004, in forum: Python
    Replies:
    0
    Views:
    303
    Raymond L. Buvel
    Nov 28, 2004
  3. Ray Buvel
    Replies:
    6
    Views:
    513
    Raymond L. Buvel
    Nov 28, 2004
  4. Raymond L. Buvel

    [ANN] rpncalc-1.1 RPN Calculator For Python

    Raymond L. Buvel, Dec 21, 2004, in forum: Python
    Replies:
    0
    Views:
    321
    Raymond L. Buvel
    Dec 21, 2004
  5. matt
    Replies:
    5
    Views:
    126
Loading...

Share This Page