- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find nth Fibonacci term in Python

Suppose we have a number n. We have to find the nth Fibonacci term by defining a recursive function.

So, if the input is like n = 8, then the output will be 13 as first few Fibonacci terms are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34...

To solve this, we will follow these steps −

- Define a function solve() . This will take n
- if n <= 2, then
- return n - 1

- otherwise,
- return solve(n - 1) + solve(n - 2)

## Example

Let us see the following implementation to get better understanding −

def solve(n): if n <= 2: return n - 1 else: return solve(n - 1) + solve(n - 2) n = 8 print(solve(n))

## Input

8

## Output

13

- Related Questions & Answers
- Program to find Fibonacci series results up to nth term in Python
- Program to find Nth Fibonacci Number in Python
- C++ program to find Nth Non Fibonacci Number
- Program to find Nth Even Fibonacci Number in C++
- Program to find nth term in Look and Say Sequence in Python
- C program to find nth term of given recurrence relation
- Program to check given number is a Fibonacci term in Python
- Find nth term of a given recurrence relation in Python
- Program to find last two digits of Nth Fibonacci number in C++
- Program to find Nth term divisible by a or b in C++
- Python Program for nth multiple of a number in Fibonacci Series
- C++ program to find nth term of the series 5, 2, 13 41,...
- Find Nth term (A matrix exponentiation example) in C++
- Program to print pentatope numbers upto Nth term in C
- Program to find nth term of a sequence which are divisible by a, b, c in Python

Advertisements