Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.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.047 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'python': 0.08; '21,': 0.09; 'valueerror:': 0.09; 'pm,': 0.10; 'wrote:': 0.14; 'coded': 0.16; 'except:': 0.16; 'int):': 0.16; 'input': 0.17; 'cc:addr :python-list': 0.17; 'cheers,': 0.19; 'programming': 0.19; 'header :In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'function': 0.25; "i'm": 0.27; 'message-id:@mail.gmail.com': 0.28; 'e.g.': 0.29; 'sat,': 0.29; 'subject:?': 0.29; 'cc:addr:python.org': 0.30; '\xc2\xa0\xc2\xa0\xc2\xa0': 0.30; 'print': 0.31; 'this.': 0.31; 'programming.': 0.32; 'does': 0.33; 'things': 0.33; 'chris': 0.34; 'normally': 0.34; 'there': 0.35; 'explicit': 0.35; 'try:': 0.35; 'quite': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'ways': 0.37; 'processing': 0.38; 'hello,': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'generate': 0.60; 'experts': 0.63; 'subject:this': 0.76; 'sender:addr:chris': 0.84; 'series:': 0.84; 'received:209.85.218.46': 0.91; 'received:mail- yi0-f46.google.com': 0.91; 'subject:there': 0.91; 'subject:better': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=/lO7robNS1SCMjYGE1HhTkS5HuO5AleUBvnW9/7Iq4k=; b=OpfXBFshZyxkvYPtwTZWEY8gtz9U69OyqhXUzXMFhU8EHgyUkDhzyFWORoQrfYJbaQ RP/5AIScKnawzr2WrFl0qk5bN0Nk6Hjx10DHk1/u7YlHKiXG76HBkA+o5ZnGAveATULo Hn4o0ehzdyNTICj8RQyr0gerQGC5JGw8hmfoQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=M9smFqsktJwPHrhLESEX3Kp0kO0Jg+gIvvua6LWJU7VmLyfLWYNrtaCVjrk/iJg8hH t6vwQujp50z+Gu8wWXVUIBDfo2CyPU28+rRQRkjACIbGxc9Xa0t8iLmCxoBcWnW5zrxK qYLHIbfLS15iFztHNEB3WkDnR+tshYhnNK9iw= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Sat, 21 May 2011 23:42:00 -0700 X-Google-Sender-Auth: aXT_nGkgndTH8Vsu70I7dROc0C4 Subject: Re: Is there a better way to solve this? From: Chris Rebert To: Ganapathy Subramanium Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 50 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306046523 news.xs4all.nl 49044 [::ffff:82.94.164.166]:41503 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5962 On Sat, May 21, 2011 at 11:28 PM, Ganapathy Subramanium wrote: > Hello, > > I'm a new bie to python programming and on the processing of learning pyt= hon > programming. I have coded my first program of fibonnaci generation and wo= uld > like to know if there are better ways of achieving the same. > > I still feel quite a few things to be improved. Just wanted experts thoug= hts > on this. > > try: > > =C2=A0=C2=A0=C2=A0 length =3D input('Enter the length till which you want= to generate the > fibonnaci series: \n') > =C2=A0=C2=A0=C2=A0 print type(length) > > except: > =C2=A0=C2=A0=C2=A0 print 'Invalid input detected' > =C2=A0=C2=A0=C2=A0 exit(0) Never use the input() function in Python 2.x; it does an eval(), which is evil. Always use raw_input() and an explicit conversion instead; e.g. Q =3D 'Enter the length till which you want to generate the fibonnaci serie= s: \n' try: length =3D int(raw_input(Q)) except ValueError: print 'Invalid input detected' exit(0) Also, as a sidenote: > if type(length) is int: Is normally written: if isinstance(length, int): Cheers, Chris -- http://rebertia.com