You are viewing a single comment's thread. Return to all comments →
Solution of Kaprekar Numbers in Python :
def kaprekarNumbers(p, q): # Write your code here li=[] for i in range(p , q+1): if(i ==1): li.append(i) elif(i == 2 or i==3 ): continue elif(i>3): num= i*i digitsize = len(str(i)) strnum=str(num) leftsize = len(strnum)-digitsize left = int(strnum[:leftsize]) right= int(strnum[leftsize:]) add = left + right if( add == i ): li.append(i) if(len(li) >0): for i in range(0,len(li)): print(li[i] ,end=" ") 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 →
Solution of Kaprekar Numbers in Python :