Can python find fibonacci series in a single line of code?

David Brown david at no.westcontrol.spam.com
Mon Nov 11 11:09:27 EST 2002


"Pittaya" <a_human_work at hotmail.com> wrote in message
news:fa61a3d8.0211110720.16a645f8 at posting.google.com...
> My Perl-addicted friend shows me that he can find fibanicci series in
> a single line of code.
>
> perl -le '$b=1; print $a+=$b while print $b+=$a'
>
> can python do something like this?

No, I don't think you can make a loop that continuously prints out anything
within a single line (and without defining another function).

But can perl do something like this:

a, b = 1, 1
while 1 :
    a, b = b+a, a
    print a

It does the same thing - the big difference is in readability.  Why you
might want to do this on a single line is beyond me.






More information about the Python-list mailing list