Fibonacci Sequence
beginnerEnd of course
You made it to the end.
That's the last lesson in Intro to Python.
Back to courseEnd of course
That's the last lesson in Intro to Python.
Back to courseOutput will appear here...
Write a function fibonacci(n) that returns the nth number in the Fibonacci sequence (0-indexed, with fibonacci(0) == 0 and fibonacci(1) == 1). Every number after that is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, ...
Tip
You can solve this recursively, but an iterative loop will be faster for large n.
The starter code reads n from input and prints the result. For an input of 10, a correct solution prints 55. Press Run to try your code on the sample input, and Submit to check it against every test, including hidden ones.
No comments yet. Start the discussion.