Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.038 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'elegant': 0.07; 'solution,': 0.09; 'subject:number': 0.09; 'subject:Help': 0.11; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'left,': 0.16; 'wrote:': 0.18; 'print': 0.22; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'closer': 0.31; 'comparison': 0.31; 'trivial': 0.31; 'fri,': 0.33; 'subject:the': 0.34; 'received:209.85': 0.35; 'problem.': 0.35; 'received:209.85.220': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'received:209': 0.37; 'work?': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'how': 0.40; 'mar': 0.68; 'fortunately': 0.84; '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=gziH4QTFtWppHtGx9qpbgrnpCp5e4opZOar5YnG2Btc=; b=wLZcXN06dr5rdkTYM9GJYgn/YLANx+oNDemTYswiqQxYv2VRYaXGQMBWSVWvMSHC3D 0Y5HNZbwsRu+SDFRU/8s8ltD+T7WqPczF8uyXsKgG3jykE6YIBXgPFT0YSNjxWMIpzDz hVNgl2I22JvD7Srn83IVeaFLd/52gNbpc+pitqVbMtGUeC+5w03QR3HbFXKj1D0IcBQJ 9U3CkyZSovVEpQyBnJV/paY4ySc5WdLbfBO1jlSKPCRb5xl+ccmxgFmaCxwOn1xGcREh /asYraUET2rzhdFWMC26rFx+7uNK/AHn9UPHgViu/Wk+W1MBjJDdVpB57ekkS62pDRzy chCw== MIME-Version: 1.0 X-Received: by 10.220.103.7 with SMTP id i7mr27959180vco.7.1364491039224; Thu, 28 Mar 2013 10:17:19 -0700 (PDT) In-Reply-To: References: <7764e61c-e4cc-413a-a76d-2d37f39abc61@googlegroups.com> Date: Fri, 29 Mar 2013 04:17:19 +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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364491047 news.xs4all.nl 6847 [2001:888:2000:d::a6]:58059 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42172 On Fri, Mar 29, 2013 at 4:03 AM, Jussi Piitulainen wrote: > def print_digits(num): > left, last = divmod(num, 10) > if left < 0: print the digits of left > print(last) > > How do you print the digits of left? With print_digits. Why does it > work? Because you only call print_digits again when left is closer to > zero than num. > > It's called recursion. An elegant solution, but buggy, I'm afraid... fortunately it's a trivial problem. The comparison should be left>0. :) ChrisA