• + 0 comments

    Python3:

    def isFibo(n):
        test_1 = 5 * (n**2) + 4
        test_2 = 5 * (n**2) - 4
        
        # If n is a fibonacci number then test_1 or test_2 must be a perfect square
        
        if int(math.sqrt(test_1)) ** 2 == test_1 or int(math.sqrt(test_2)) ** 2 == test_2:
            return 'IsFibo'
        else:
            return 'IsNotFibo'