水仙花数

 1 '''
 2 水仙花数是指一个 n 位正整数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。
 3 (例如:1^3 + 5^3+ 3^3 = 153)。
 4 要求:从100-999个数,打印输出所有的"水仙花数" 5 '''
 6 
 7 ---------方法一
 8 for i in range(100,1000):
 9     x = int(i/100)#百位数
10     y = int((i%100)/10)
11     z = i%10
12     if i == x**3 + y**3 + z**3:
13        print(i,end=',')
14 
15 
16 
17 ---------方法二
18 import math
19 
20 for i in range(100,1000):
21     x = math.floor(i/100) # floor:取小于等于x的最大的整数值,如果x是一个整数,则返回自身
22     y = math.floor((i-x*100)/10)
23     z = i - math.floor(i/10)*10
24     if i == x**3 + y**3 + z**3:
25        print(i,end=',')
为什么要坚持,想一想当初!
原文地址:https://www.cnblogs.com/JerryZao/p/8685600.html