How to check if a given number is Fibonacci number?

PHOTO EMBED

Fri Nov 25 2022 12:04:20 GMT+0000 (Coordinated Universal Time)

Saved by @KarenHolton #education #assignment #homework #student #study #university #python #programming

import math 
 
def isPerfectSquare(x):
    s = int(math.sqrt(x))
    return s*s == x
 
 
def isFibonacci(n):
 
    # n is Fibonacci if one of 5*n*n + 4 or 5*n*n - 4 or both
    # is a perfect square
    return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n - 4)
 
 for i in range(1, 11):
    if (isFibonacci(i) == True):
        print(i, "is a Fibonacci Number")
    else:
        print(i, "is a not Fibonacci Number ")
content_copyCOPY

https://www.solidworksassignmenthelp.com/