第一篇贡献给python计算happy number~
def cal(n): s=str(n) sum=0 for i in range(len(s)): sum+=int(s[i])**2 return sum a=77 # 13 139 ok; 4 5 6 not # print (cal(a)) def itr(a): log_set=set([a]) while a!=1: temp = cal(a) if temp in log_set: return False # False but not false else: log_set.add(temp) a=temp # lost as testing online return True print ("itr(a): ",itr(a))