其他分享
首页 > 其他分享> > 快乐的数字

快乐的数字

作者:互联网

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)

结果是:

 

标签:10,num,数字,lucky,range,快乐,print,happy
来源: https://www.cnblogs.com/cz944524/p/15265204.html