
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- Program to find Fibonacci series results up to nth term in Python
- Program to find Nth Fibonacci Number in Python
- Program to find Nth Even Fibonacci Number in C++
- C++ program to find Nth Non Fibonacci Number
- Program to find nth term in Look and Say Sequence in Python
- Program to find last two digits of Nth Fibonacci number in C++
- Program to check given number is a Fibonacci term in Python
- Python Program for nth multiple of a number in Fibonacci Series
- C program to find nth term of given recurrence relation
- Program to find Nth term divisible by a or b in C++
- Find nth term of a given recurrence relation in Python
- Program to find nth term of a sequence which are divisible by a, b, c in Python
- Program to find length of longest fibonacci subsequence in Python
- Python Program to Find the Fibonacci Series Using Recursion
- Java Program for nth multiple of a number in Fibonacci Series

Advertisements