Challenge 3: Fibonacci Sequence

Practice your concepts of recursion by writing a function to calculate the Fibonacci sequence.

Problem Statement

In this exercise, you have to write a recursive function fibonacci that takes an integer range as a parameter and returns the nthnth number from the Fibonacci Sequence where nn is the value of the range variable.

Input

an integer

Output

nthnth value of the fibonacci sequence.

Sample Input

$range = 7

Sample Output

The fibonacci sequence up till the 7th7th index will be as follows:

0 1 1 2 3 5 8 13

Therefore, the output will be:

13

Coding Exercise

Write your code in the code widget below. If you don’t get it right, don’t fret; the solution is also given.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy