Skip to main content
Practice

Coding Quiz - Fibonacci Sequence

In this coding challenge, you will implement the Fibonacci sequence from scratch.

The Fibonacci sequence is a series where each term is the sum of the two preceding ones.

For example, if the first and second terms are 1, then the sequence proceeds as 1, 1, 2, 3, 5, 8, 13, ...

Write a function that takes an integer n from the user and returns the nth term of the Fibonacci sequence, with the first and second terms being 1.


Code Implementation
def solution(n):
# Write your code here
return



Constraints

  • The input n must be an integer and should be 1 or greater.

  • The function must be implemented recursively.




Example Input and Output

  • Input: 5

  • Output: 5

  • Explanation: The 5th term of the Fibonacci sequence is 1, 1, 2, 3, 5. Therefore, the 5th term is 5.


  • Input: 7

  • Output: 13

  • Explanation: The 7th term of the Fibonacci sequence is 1, 1, 2, 3, 5, 8, 13. Therefore, the 7th term is 13.