werid python troubles...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronparker
    New Member
    • Aug 2010
    • 27

    werid python troubles...

    Hello,
    I am just having a little trouble getting python to work correctly. When I try to divide 10 by 3 I get 3 instead of 3.3333 or when I do 1/3 i get 0.
    Code:
    >>> 10/3
    3
    >>> 1/3
    0
    Any ideas as to what is causing this and how i can fix it??
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You are seeing the results of integer division. Convert one of the numbers to float or import division from the __future__ module.
    Code:
    >>> 1/3
    0
    >>> from __future__ import division
    >>> 1/3
    0.33333333333333331
    >>> float(1)/3
    0.33333333333333331
    >>>

    Comment

    Working...