• + 0 comments

    Python 3 solution:

    def is_kaprekar(n):
        sn = str(n * n)
        sn = '0' + sn if len(sn) % 2 else sn
        d = len(str(n))
        return int(sn[-d:]) + int(sn[:-d]) == n
    
    
    def kaprekarNumbers(p, q):
        # Write your code here
        numbers = []
    
        for i in range(p, q + 1):
            if is_kaprekar(i):
                numbers.append(str(i))
    
        if len(numbers):
            print(*numbers)
        else:
            print("INVALID RANGE")