Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'operator': 0.03; 'float': 0.05; '(so': 0.07; 'subject:help': 0.07; 'python': 0.09; 'expectation': 0.09; 'integers': 0.09; 'modulo': 0.09; 'rounds': 0.09; 'sep': 0.09; 'zero.': 0.09; 'subject:python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'helps!': 0.16; 'infinity,': 0.16; 'stuff.': 0.16; 'wrote:': 0.17; 'yield': 0.17; '(or': 0.18; 'received:209.85.214.174': 0.21; 'mention': 0.23; 'second': 0.24; 'so.': 0.24; 'allows': 0.25; 'header:In-Reply-To:1': 0.25; 'checking': 0.27; 'message-id:@mail.gmail.com': 0.27; '0.5': 0.29; '>>>>': 0.29; 'fri,': 0.30; 'basic': 0.30; 'helpful': 0.30; 'problem': 0.33; 'to:addr:python-list': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'problem,': 0.35; 'doing': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'two': 0.37; 'maintaining': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'positive': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'kindly': 0.67; 'brand': 0.78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=FjJ830/nULCNp1+xRfm5DKZj13X1eyUcpBB5vhIPNYo=; b=tlVGywmUgXTMqSGjCBAmHgchgEALKVkIa/sRLv+I2GcUJZ+E6wfZZSr87jkRjclKZC zFHRFbRdXTuiNt4f82coDLnQF2q5o9t4zPZNnjuVFjOm4/Xf3WmeX2N7X4K0Exx1swbP TaTMC8kvYOMSTLrXw36m3Zzus0/mBqPOTujUs0k8UXac8gEdvwxqq94KqBTrJUuJvZXN G3AjE1HYA9VwYqj5OVKPExMlkJx5n7UIPX28HoHzpFcvn/eMZgHRoB199wLnjzDHEnnG 6XVDoOWCp3XgPYeUfPAgzz4ohGrDrxxO1KGg+JwrYBi4VA/txvq7SW60fsxewjBXmguQ OfvQ== MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 7 Sep 2012 23:06:19 +1000 Subject: Re: Division help in python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347023611 news.xs4all.nl 6981 [2001:888:2000:d::a6]:41633 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28684 On Fri, Sep 7, 2012 at 10:53 PM, Ramyasri Dodla wrote: > I am brand new to python. checking over basic stuff. I came across the > problem while doing so. If any body aware of the problem, kindly respond me. > >>>> 5/10 > 0 >>>> - 5/10 > -1 > > The second case also should yield a 'zero' but it is giving a -1 You're clearly using Python 2, because in Python 3, the / operator will return a float instead (so these would return 0.5 and -0.5 respectively). But it's helpful to mention what Python version you're using when you ask for help :) The reason for this is that / (or in Python 3, //) rounds toward negative infinity, not toward zero. This allows the modulo operator (%) to return a positive number, while still maintaining the normal expectation that: (x//y)*y + (x%y) == x for any two integers x and y. Hope that helps! ChrisA