- 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 check given number is a Fibonacci term in Python

Suppose we have a number say n. We have to check whether n is present in Fibonacci sequence or not. As we know in Fibonacci sequence f(i) = f(i-1) + f(i-2) for each i from 2 to n, and f(0) = 0, f(1) = 1.

So, if the input is like n = 13, then the output will be True, as some terms in Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, so 34 is present.

To solve this, we will follow these steps −

- phi := 0.5 + 0.5 * square root of(5.0)
- a := phi * n
- return true when n is same as 0 or a is an integer

## Example

Let us see the following implementation to get better understanding −

from math import sqrt def solve(n): phi = 0.5 + 0.5 * 5.0**0.5 a = phi * n return n == 0 or abs(round(a) - a) < 1.0 / n n = 13 print(solve(n))

## Input

13

## Output

True

- Related Questions & Answers
- How to check if a given number is a Fibonacci number in Python Program ?
- Python Program for How to check if a given number is a Fibonacci number?
- Java Program for check if a given number is Fibonacci number?
- Program to find nth Fibonacci term in Python
- Python program to check if the given number is a Disarium Number
- Python program to check if a given string is number Palindrome
- Python program to check if the given number is Happy Number
- Java program to print Fibonacci series of a given number.
- C program to find Fibonacci series for a given number
- Program to find Fibonacci series results up to nth term in Python
- Check whether a number is a Fibonacci number or not JavaScript
- Program to check whether given number is Narcissistic number or not in Python
- Program to find Nth Fibonacci Number in Python
- N-th Fibonacci number in Python Program
- Python Program to Check if a Number is a Perfect Number

Advertisements