问题描述:水仙花链接
参见回答:
Python算水仙花数的程序怎么改进?www.zhihu.com![699104d23097804b945e348088e8b964.png](https://i-blog.csdnimg.cn/blog_migrate/d730e3dd7fd2f31ef473b19a078b5543.png)
代码:
"""
寻找水仙花
* / % // 乘,除,余数,整除
"""
#获得最高位数
def max_num(x):
len_int = len(str(x))
# print('整数长度:{}'.format(len_int), '--')
return (x // 10 ** (len_int - 1))
def Find_daffodil(x):
x1 = x
list1 = []
i = len(str(x1))
j = max_num(x1)
# print(j)
list1.append(j)
while x1 - j * 10 ** (i - 1) != 0:
x1 -= j * 10 ** (i - 1)
i = len(str(x1))
j = max_num(x1)
# print(j)
list1.append(j)
# print(list1)
sum1 = 0
for k, a0 in enumerate(list1):
# print(a0)
sum1 += a0**(len(str(x)))
return(sum1)
print('=========')
for i in range(1000000):
if Find_daffodil(i) - i == 0:
print(i)
=========
0
1
2
3
4
5
6
7
8
9
153
370
371
407
1634
8208
9474
54748
92727
93084
548834
完美数
![7122f91c0a98bdcd99b2508f5c3c8b14.png](https://i-blog.csdnimg.cn/blog_migrate/295fbdd6f3f1da64134a158a8c6d6b36.jpeg)
def