Coding Quiz - Fibonacci Sequence
In this coding challenge, you will implement the Fibonacci sequence from scratch.
The Fibonacci sequence consists of numbers 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.
def solution(n): # Write your code here return
Constraints
-
The input
nmust be an integer and should be 1 or greater. -
The function must use recursion.
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.
Lessons in this chapter · Practical Python Algorithms
- 1. Advanced Python Algorithms
- 2. What is a Recursive Call?
- 3. Implementing Fibonacci Sequence with Recursive Function
- 4. Fill-in-the-blank quiz
- 5. Coding Quiz - Fibonacci Sequence
- 6. Dynamic Programming and Divide and Conquer
- 7. Implementing Dynamic Programming in Python
- 8. Multiple-choice quiz
- 9. Coding Quiz - Make One
- 10. What is Merge Sort?
- 11. Implementing Merge Sort
- 12. Multiple-choice quiz
- 13. Coding Quiz - Sort a List Using Merge Sort
- 14. What is Quick Sort?
- 15. Implementing Quick Sort in Python
- 16. Multiple-choice quiz
- 17. Coding Quiz - Sort a List Using Quick Sort
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help