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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'example:': 0.03; 'output': 0.05; 'learn,': 0.09; 'subject:number': 0.09; 'subject:Help': 0.11; 'python': 0.11; 'division.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ignoring': 0.16; 'remainder': 0.16; 'wrote:': 0.18; 'producing': 0.19; 'input': 0.22; 'putting': 0.22; 'print': 0.22; 'finally,': 0.24; 'integer': 0.24; 'post': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'division': 0.31; 'gather': 0.31; 'operators': 0.31; 'produces': 0.31; 'probably': 0.32; 'fri,': 0.33; 'subject:the': 0.34; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'positive': 0.37; 'two': 0.37; 'list': 0.37; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'that,': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'numbers': 0.61; 'simply': 0.61; "you're": 0.61; 'here:': 0.62; "you'll": 0.62; 'mar': 0.68; 'answer.': 0.68; 'gathering': 0.68; 'honest': 0.78; 'subject:printing': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=JRaPbRVtXzr4Imjd+cNbdWoHdnQngj2WX8vr4He2BQQ=; b=i5HRCeooWx4C3xWccfvTA+zvqOh5069ALTrmwZt+HygIkATZbmJHlH1HZ1JedHuM5B /iHAvRWoiWAZneEN8IgHAyuOv2/flC0p6hE68zc12n0JEUGdGJlHIPxTJ9Ww0dbsRixX 1farSMXvDL3PF3EyAvw7ZiqFkQdNdR+/EVcPlf5EfGLpct1S1CeLdT/xwaLQW1vEc9uv wtK1gSAtjnK2vvVbUmfj1pf0DeYjIvKujuPhCUaUsFMe9yTJXe3YBvtwq0rzf263AVok GCzFqo9Ryi9gRx8ijE0V6WIXiOwnyMtV26aoXZGHGnRO08nYsgUZEGr05O5yEw6zsa1r u8TA== MIME-Version: 1.0 X-Received: by 10.58.253.161 with SMTP id ab1mr26948640ved.55.1364482105774; Thu, 28 Mar 2013 07:48:25 -0700 (PDT) In-Reply-To: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> References: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> Date: Fri, 29 Mar 2013 01:48:25 +1100 Subject: Re: Help printing the integers of a longer number 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364482107 news.xs4all.nl 6990 [2001:888:2000:d::a6]:37369 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42134 On Fri, Mar 29, 2013 at 1:39 AM, wrote: > I want to print the individual numbers of a large number using division and modulus division. > > For example: > > Enter a positive integer: 54321 > 5 > 4 > 3 > 2 > 1 Python has two operators that can help here: // for integer division - returns the quotient without the remainder % for modulus - returns the remainder You'll also want to use a while loop to continue gathering digits so long as there's something left in the number. And if you want the digits to come out in that order, you're probably going to want to gather them into a list and then output them in reverse. But start by ignoring that part and producing something that, for the input 54321, produces 1, 2, 3, 4, and then 5. Finally, when you're asking about homework, please be honest about it. We can tell, you're not putting one over us :) Better still, post your non-working code and explain where you're having trouble; we'll be happy to help you learn, but we won't simply give you the answer. ChrisA