Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5962
| References | <BANLkTinj1qbeuc=X_u5n-_Rdwi4AaD914w@mail.gmail.com> |
|---|---|
| Date | 2011-05-21 23:42 -0700 |
| Subject | Re: Is there a better way to solve this? |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1906.1306046523.9059.python-list@python.org> (permalink) |
On Sat, May 21, 2011 at 11:28 PM, Ganapathy Subramanium
<sganapathy.subramanium@gmail.com> wrote:
> Hello,
>
> I'm a new bie to python programming and on the processing of learning python
> programming. I have coded my first program of fibonnaci generation and would
> 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 thoughts
> on this.
>
> try:
>
> length = input('Enter the length till which you want to generate the
> fibonnaci series: \n')
> print type(length)
>
> except:
> print 'Invalid input detected'
> 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 = 'Enter the length till which you want to generate the fibonnaci series: \n'
try:
length = 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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Is there a better way to solve this? Chris Rebert <clp2@rebertia.com> - 2011-05-21 23:42 -0700
csiph-web