python only prints integers

geremy condra debatem1 at gmail.com
Thu Jan 6 17:58:28 EST 2011


On Thu, Jan 6, 2011 at 2:49 PM, francesco
<cerutti.francesco.to at gmail.com> wrote:
> I'm pretty new in Python language. I have a problem with numbers: it
> seems python doesn't know any more how to count!
> I get only the down rounded integer
> 20/8 = 2
> 8/3=2
> I probably changed some option to round the numbers, but I don't
> remember how.
> Is there a way to reset the number of digits to default?
> Thanks in advance

Use floats instead of integers:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 20/8
2
>>> 20.0/8
2.5


or use Python3:

Python 3.2a1 (r32a1:83318, Aug 13 2010, 22:32:03)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 20/8
2.5
>>> 20.0/8
2.5



More information about the Python-list mailing list