You are viewing a single comment's thread. Return to all comments →
Python 3
def kaprekarNumbers(p, q): # Write your code here kapN = [] for i in range(p, q+1, 1): sqr = str(i**2) if i == 1: kapN.append(str(i)) elif len(sqr) < 2: pass else: d = math.ceil(len(sqr) / 2) r = int(sqr[-d:]) l = int(sqr[:-d]) if r > 0 and l > 0 and r+l == i: kapN.append(str(i)) if len(kapN) == 0: print('INVALID RANGE') print(' '.join(kapN))
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
Python 3