打印出100-999所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。
sxh = [] for i in range(100, 1000): s = 0 m = list(str(i)) for j in m: s = int(j)**len(m) if i == s: print(i) sxh.append(i) print("100-999的水仙花数:s" sxh)
sxh = [] for i in range(100, 1000): s = 0 m = list(str(i)) for j in m: s = int(j)**len(m) if i == s: print(i) sxh.append(i) print("100-999的水仙花数:s" sxh)