division bug?

Discussion in 'Python' started by Milan, Jun 9, 2004.

  1. Milan

    Milan Guest

    a program:

    a=10
    b=5
    print a/b

    and its result: 0. If you run the program, you see always a sero (0),
    but 10/5 is 2. Who can help me?
    Milan, Jun 9, 2004
    #1
    1. Advertising

  2. Milan

    Russell Blau Guest

    "Milan" <> wrote in message
    news:...
    > a program:
    >
    > a=10
    > b=5
    > print a/b
    >
    > and its result: 0. If you run the program, you see always a sero (0),
    > but 10/5 is 2. Who can help me?


    Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
    win32
    Type "copyright", "credits" or "license()" for more information.

    >>> a = 10
    >>> b = 2
    >>> print a/b

    5

    What version are *you* running?


    --
    I don't actually read my hotmail account, but you can replace hotmail with
    excite if you really want to reach me.
    Russell Blau, Jun 9, 2004
    #2
    1. Advertising

  3. On 2004-06-09, Milan <> wrote:
    > a program:
    >
    > a=10
    > b=5
    > print a/b
    >
    > and its result: 0. If you run the program, you see always a zero (0),


    What answer do you want?

    > but 10/5 is 2. Who can help me?


    Perhaps you can. :)

    >>> 5/10

    0
    >>> 5.0/10.0

    0.5
    >>> 5//10

    0
    >>> 5.0//10.0

    0.0

    --
    Grant Edwards grante Yow! Hold the MAYO & pass
    at the COSMIC AWARENESS...
    visi.com
    Grant Edwards, Jun 9, 2004
    #3
  4. Milan

    Duncan Booth Guest

    (Milan) wrote in
    news::

    > a program:
    >
    > a=10
    > b=5
    > print a/b
    >
    > and its result: 0. If you run the program, you see always a sero (0),
    > but 10/5 is 2. Who can help me?
    >
    >


    I don't know who can help you, but this is a Python newsgroup and if you
    try your program in Python it prints 2, so perhaps you are using some other
    language:

    >>> a=10
    >>> b=5
    >>> print a/b

    2

    If you are using Python, try cutting and pasting the exact code and the
    problem you think you see, and we can try to help you from there.
    Duncan Booth, Jun 9, 2004
    #4
  5. Milan> a program:
    Milan> a=10
    Milan> b=5
    Milan> print a/b

    Milan> and its result: 0. If you run the program, you see always a sero
    Milan> (0), but 10/5 is 2. Who can help me?

    Works for me:

    % python
    Python 2.4a0 (#25, May 22 2004, 15:16:21)
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1493)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> a=10
    >>> b=5
    >>> print a/b

    2

    I think you'll need to give more details (platform, version, actual
    interpreter output, etc) to get any more useful help.

    Skip
    Skip Montanaro, Jun 9, 2004
    #5
  6. Milan wrote:

    > a program:
    >
    > a=10
    > b=5
    > print a/b
    >
    > and its result: 0. If you run the program, you see always a sero (0),
    > but 10/5 is 2. Who can help me?


    You probably have reversed a & b in your program somewhere. Zero is the
    correct result with the numbers reversed.

    >>> a = 10
    >>> b = 5
    >>> print "a/b = %s\nb/a = %s" % (a/b, b/a)

    a/b = 2
    b/a = 0

    If you import division from __future__ my guess is that you will see the
    result of 0.5. If this is the case you have mixed a & b up somewhere.

    >>> from __future__ import division
    >>> print "a/b = %s\nb/a = %s" % (a/b, b/a)

    a/b = 2.0
    b/a = 0.5


    --
    Steven Rumbalski
    news|at|rumbalski|dot|com
    Steven Rumbalski, Jun 9, 2004
    #6
    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. walala
    Replies:
    12
    Views:
    1,859
  2. sunwij

    FLOATING POINT DIVISION

    sunwij, Dec 28, 2003, in forum: VHDL
    Replies:
    3
    Views:
    1,014
    sunwij
    Dec 29, 2003
  3. Michael Yanowitz

    Negative division bug?

    Michael Yanowitz, Aug 3, 2006, in forum: Python
    Replies:
    1
    Views:
    254
  4. Replies:
    94
    Views:
    4,392
    ┬Ča\\/b
    Feb 9, 2007
  5. Snail

    Division/math bug in perl?

    Snail, Feb 24, 2005, in forum: Perl Misc
    Replies:
    25
    Views:
    257
    Geoff
    Feb 25, 2005
Loading...

Share This Page