WTF is Fibonnacci
Nick Vargish
nav at adams.patriot.net
Thu Jun 19 15:08:07 EDT 2003
"Mike" <ss3canon at earthlink.net> writes:
> I'm readin through the Non-Programers Tutorial for Python and I'm on the
> examples of section Count to 10. And I can't figure out how the example got
> the output, can anyone help break it down for me?
Hmm, going by the Subject: line, you want to know what a Fibonacci
sequence is.
That's a sequence in which the next number is the sum of the previous
two numbers:
1 1 2 3 5 8 13 21 [ .. ]
For example:
def fib(n):
l = [ 1, 1 ]
if n < 3:
return l[:n]
for i in range(n -2):
l.append(l[-1] + l[-2])
return l
Hope that helps,
Nick
--
#include<stdio.h> /* SigMask 0.3 (sig.c) 19990429 PUBLIC DOMAIN "Compile Me" */
int main(c,v)char *v;{return !c?putchar(*v-1)&&main(0,v+ /* Tweaks welcomed. */
1):main(0,"Ojdl!Wbshjti!=obwAqbusjpu/ofu?\v\1");} /* build: cc -o sig sig.c */
More information about the Python-list
mailing list