• + 1 comment

    for Python3 Platform

    def kaprekarNumbers(p, q):
        flag = 0
        
        for i in range(p, q+1):
            d = 0
            temp = i
            
            while (temp > 0):
                d += 1
                temp = temp//10
            
            square = i*i
            
            if (square//pow(10, d) + square % pow(10, d) == i):
                flag = 1
                print(i, end=" ")
        
        if (flag == 0):
            print("INVALID RANGE")
    
    p = int(input())
    q = int(input())
    
    kaprekarNumbers(p, q)