We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def kaprekarNumbers(p, q):
kap=[]
for i in range(p,q+1):
sqr=str(i*i)
r=sqr[len(sqr)-len(str(i))::]
l=round(int(sqr)/(10**len(r)),0)
if l+int(r)==i:
kap.append(i)
if len(kap)!=0:
print(*kap, sep=" ")
else:
print("INVALID RANGE")
Cookie support is required to access HackerRank
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
def kaprekarNumbers(p, q): kap=[] for i in range(p,q+1): sqr=str(i*i) r=sqr[len(sqr)-len(str(i))::] l=round(int(sqr)/(10**len(r)),0) if l+int(r)==i: kap.append(i) if len(kap)!=0: print(*kap, sep=" ") else: print("INVALID RANGE")