You are viewing a single comment's thread. Return to all comments →
My solution, if you see any improvements in the code, plase let me know:
def kaprekarNumbers(p, q): count = 0 for i in range(p,q+1): op = str(i**2) count_digit = str(i) count_digit = len(count_digit) right = op[-count_digit:] left = op[:(len(op)-count_digit)] if len(right)== 0: left = int(left) right = 0 elif len(left)== 0: right = int(right) left=0 else: right = int("".join(str(num) for num in right)) left = int("".join(str(num) for num in left)) if right + left == i: print(i,end=' ') count+=1 if count == 0: print('INVALID RANGE')
Seems like cookies are disabled on this browser, please enable them to open this website
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
My solution, if you see any improvements in the code, plase let me know: