快乐的数字

def lucky(num): 
b = 0
for i in range(10):
if num // (10**i) == 0: 
x = i
break
if num == 1: 
print(True)
elif num < 10: 
print(False)
else:
c = num
for j in range(x-1): 
b = b + (c%10)**2 
c = c//10 
b = b + c**2
num = b
return lucky(num) 
happy = eval(input())
lucky(happy)

结果是:

快乐的数字

 

上一篇:python -- 字符串的各种用法


下一篇:“create-react-app myapp 创建失败”的总结