Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def sum_sq_digits(n):
ans=0
for i in str(n):
ans+=int(i)*int(i)
return ans
def is_happy(n):
if len(str(n))==1:
if n==1:
return 'It is a Happy Number'
else:
return 'It is not a happy number'
else:
n=sum_sq_digits(n)
return is_happy(n)
print(is_happy(12))
print(is_happy(28))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment