- for循环(第一种)
- for循环(第二种)
- while循环
水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身
for循环(第一种)
for b in range(10):
for s in range(10):
for g in range(10):
num = b * 100 + s * 10 + g
sx = b ** 3 + s ** 3 + g ** 3
if num == sx:
print('水仙花数有', num)
for循环(第二种)
import math
for i in range(100,1000):
if math.pow((i,10), 3) + math.pow((i // 10 % 10), 3) + math.pow((i // 100), 3) == i:
print('水仙花数有:', i)
while循环
sx = 100
while sx < 1000:
g = sx % 10
s = sx // 10 % 10
b = sx // 100
sx_num = b ** 3 + s ** 3 + b ** 3
if sx == sx_num:
print('水仙花数有', sx)
sx += 1



