Write a function to determine whether a number is a "happy number".
A "Happy number" is defined as: For a positive integer,
Each time you replace the number with the sum of the squares of the numbers at each position, and then repeat the process until the number becomes 1,
It can also be an infinite loop, but it will never change to 1. If it can become 1, then this number is the number of happy
num = input ('Please enter a number >>>'). Strip () New_num=Numifnum.isdigit (): Sum1=0 Check= [] whileSum1!=1: forIinchCheck:ifCheck.count (i) >= 2: Print(new_num+'not a happy number! ') exit () Li= [] forIinchstr (num): li.append (int (i)) L= Map (LambdaX:X * * 2, Li) ki= [] forIinchl:ki.append (i) sum1=sum (ki) check.append (sum1) Num=sum1Else: Print(new_num+'is the number of happiness! ')Else: Print('the wrong input! Not numbers! ')
View Code
"Fat House Happy Number"-python violent version