Can python find fibonacci series in a single line of code?
Bengt Richter
bokr at oz.net
Tue Nov 12 06:52:12 EST 2002
On Tue, 12 Nov 2002 09:32:35 +0000 (UTC), Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote:
>a_human_work at hotmail.com (Pittaya) wrote in
>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?
>>
>Ca you explain please (because I don't really know Perl) what a program
>that prints 1.#INF over and over again has to do with Fibonacci (at least
>thats who who I think you meant)?
>
>Jeff's nice clear Python program prints out a Fibonacci series, but the
>Perl one just seem to print a bit of a Fibonacci series which doesn't
>strike me as terribly useful. Even the numbers it does print are mostly
>approximations.
>
Here's another variant that will keep printing non-approximations (assuming a doesn't pre-exist):
while 1: print vars().setdefault('a',[1,1]) and a.append(a.pop(0)+a[0]) or a[0]
Regards,
Bengt Richter
More information about the Python-list
mailing list