- **Python**
(*http://www.velocityreviews.com/forums/f43-python.html*)

- - **python only prints integers**
(*http://www.velocityreviews.com/forums/t741653-python-only-prints-integers.html*)

python only prints integersI'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 |

Re: python only prints integersOn Thu, Jan 6, 2011 at 2:49 PM, francesco
<cerutti.francesco.to@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 |

Re: python only prints integersOn Jan 6, 3:49*pm, francesco <cerutti.francesco...@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? In Python 2, the '/' operator performs integer division by default when both its operands are integers. To change this, either place this at the top of the file: from __future__ import division or convert your numbers to floats: >>> 20.0 / 8.0 2.5 >>> float(20) / float(8) 2.5 In Python 3, the '/' operator always performs true division. |

Re: python only prints integersWell, that's because 20 is integer. To get float you can write 20.0 (or 20.).
20.0/8.0 = 2.5 8.0/3.0 = 2.6666666666666665 07.01.2011, 00:49, "francesco" <cerutti.francesco.to@gmail.com>: > 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 > > -- > http://mail.python.org/mailman/listinfo/python-list -- jabber: kost-bebix@ya.ru |

Re: python only prints integersOn 6 Gen, 23:59, Ian <ian.g.ke...@gmail.com> wrote:
> On Jan 6, 3:49*pm, francesco <cerutti.francesco...@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? > > In Python 2, the '/' operator performs integer division by default > when both its operands are integers. *To change this, either place > this at the top of the file: > > from __future__ import division > > or convert your numbers to floats: > > >>> 20.0 / 8.0 > 2.5 > >>> float(20) / float(8) > > 2.5 > > In Python 3, the '/' operator always performs true division. Thanks to all! Very quick answer! I fixed the problem by using floats. Thanks again |

Re: python only prints integersIn article <cd9d1c80-b1d2-4d20-9896-a6fd77bd7db2@j25g2000yqa.googlegroups.com>,
Ian <ian.g.kelly@gmail.com> wrote: > >In Python 3, the '/' operator always performs true division. How can I get integer division? -- -Ed Falk, falk@despams.r.us.com http://thespamdiaries.blogspot.com/ |

Re: python only prints integersOn Fri, 07 Jan 2011 03:32:54 +0000, Edward A. Falk wrote:
> In article > <cd9d1c80-b1d2-4d20-9896-a6fd77bd7db2@j25g2000yqa.googlegroups.com>, Ian > <ian.g.kelly@gmail.com> wrote: >> >>In Python 3, the '/' operator always performs true division. > > How can I get integer division? >>> 25//4 6 -- Steven |

All times are GMT. The time now is 03:16 PM. |

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.

SEO by vBSEO ©2010, Crawlability, Inc.