Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out2.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!feed.xsnews.nl!border-2.ams.xsnews.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.134.4.91.MISMATCH!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'subject:code': 0.07; 'subject:python': 0.10; 'output': 0.10; 'am,': 0.12; 'multiples': 0.16; 'received:192.168.1.104': 0.16; 'val': 0.16; 'val,': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'this?': 0.19; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; "skip:' 10": 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'values': 0.32; 'header :User-Agent:1': 0.33; 'rather': 0.33; 'that,': 0.33; 'loop': 0.34; 'something': 0.35; 'but': 0.37; 'received:192': 0.37; 'doing': 0.38; 'getting': 0.38; 'received:192.168': 0.40; 'header:Reply- To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'generator,': 0.84 Date: Mon, 21 Nov 2011 09:27:29 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: sl33k Subject: Re: Format the ouput in my python code References: <3f23c6ac-0554-4cb7-bf7c-b98c29721796@z22g2000prd.googlegroups.com> In-Reply-To: <3f23c6ac-0554-4cb7-bf7c-b98c29721796@z22g2000prd.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:wl7qkoVCg9rZ0ufbZlrSCmZINmgGxnbR2LhkGyRTrbB PzOtlARibWq5tre148Eu5VbuaUhQoRJPgD3ptE7b02PXtOeXMx wiiSRGlJD1pIbq6qYyy4vSCyzFWm1F+AOpDuoKAcDvNXZrTJ0R Li2XmilqHr+F8q+Pw8FevZcdLerGqlABCPv2zQJCqQgOxOUxsh LQzzZBz2TrefI+kbMgjiE1QfJ7M4NcVXbsnhk1KE/+AseBHS7n MNyNOL3b1G0ua8wOVEWt1dLxE742lAXBYBLXObDtyeGe9Rg43w qdsy19MBBKaVmUdM7L+vixaXnw5GHRDuHdyZbNzqUQFyVUSlw= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321885680 news.xs4all.nl 6904 [2001:888:2000:d::a6]:45254 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16010 On 11/21/2011 07:13 AM, sl33k wrote: > I am printing the numbers from 1 to 100. In that, I want to display > multiples of 3,5 and of both as mulof3, mul0f5 and mulof3and5 > respectively. > > I am getting the output I want but I would like to format the output > to print only 10 number per line. How do I go about doing this? > > for i in range(1, 101): > if i % 3 == 0: > if i % 5 == 0: > print 'mulof3and5', > else: > print 'mulof3', > elif i % 5 == 0: > print 'mulof5', > else: > print i > Change that loop into a generator, having it return values rather than printing them. Then call that generator in a for-loop, something like: for index, val in enumerate(mygen): print val, if not index%10: print -- DaveA