[Tutor] fibonacci
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Wed Feb 12 03:18:03 2003
On Tue, 11 Feb 2003, Chris Avery wrote:
> Of course, my apologies.
>
> The Fibonacci sequence is the sequence of numbers each of which, after the
> second, is the sum of the two previous ones.
>
> 0, 1, 1, 2, 3, 5, 8, 13, 21,...,
Ok, this sounds clear enough. Let's try it:
###
def fibonacci(n):
"""The Fibonacci sequence is the sequence of numbers
each of which, after the second, is the sum of the
two previous ones."""
return fibonacci(n-1) + fibonacci(n-2)
###
The above definition won't work, of course. But's it's darn close to
being correct (if not efficient). Can you think of a reason why it's
broken, and if there's a good way to fix it?
> Sorry about the confusion.
No problem; don't worry about it. The problem is a lot clearer now.
Gotta go to sleep now. Good night!