there is a problem, holp someone could help me,thanks
gordon at panix.com
Wed Aug 24 18:46:39 CEST 2011
In <f99a156b-56b4-41f4-9599-0dcc31a47b0f at v9g2000pri.googlegroups.com> kangshufan at hotmail.com writes:
> Hi everyone
> I just study python for a few time.
> Now I have a problem and I holp someone can help me.
> There is a piece of code:
> def fib(x):
> if x==0 or x==1: return 1
> else: return fib(x-1) + fib(x-2)
> Could you explain how it works?
> Thanks for you help.
When a function calls itself, as fib() does, it's called recursion.
Basically the fib() method keeps calling itself with smaller and smaller
arguments until it gets 1 or 0.
John Gordon A is for Amy, who fell down the stairs
gordon at panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
More information about the Python-list