You are viewing a single comment's thread. Return to all 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")
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 →
Python 3 solution: