- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- 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 Number in Python

Suppose we have a number n, we have to find the nth Fibonacci term. As we know the ith Fibonacci term f(i) = f(i-1) + f(i-2), the first two terms are 0, 1.

So, if the input is like 15, then the output will be 610

To solve this, we will follow these steps −

- first := 0, second := 1
- for i in range 2 to n, do
- temp := first + second
- first := second
- second := temp

- return second

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, n): first = 0 second = 1 for _ in range(2, n+1): temp = first + second first = second second = temp return second ob = Solution() print(ob.solve(15))

## Input

15

## Output

610

- Related Articles
- Program to find nth Fibonacci term in Python
- C++ program to find Nth Non Fibonacci Number
- Program to find Nth Even Fibonacci Number in C++
- Program to find last two digits of Nth Fibonacci number in C++
- Program to find Fibonacci series results up to nth term in Python
- Python Program for nth multiple of a number in Fibonacci Series
- Java Program for nth multiple of a number in Fibonacci Series
- N-th Fibonacci number in Python Program
- Nth Catalan Number in Python Program
- Write a C# function to print nth number in Fibonacci series?
- Program to find nth smallest number from a given matrix in Python
- Program to find nth ugly number in C++
- Program to find minimum number of Fibonacci numbers to add up to n in Python?
- Python Program for n-th Fibonacci number
- Python Program for nth Catalan Number

Advertisements