代碼:
num = 100
while num <= 999:
a = num // 100
b = (num - a * 100) // 10
c = num % 10
if num == a**3 + b**3 + c**3:
print( num, "是水仙花數")
num += 1
執行結果:
153 是水仙花數
370 是水仙花數
371 是水仙花數
407 是水仙花數
代碼:
num = 100
while num <= 999:
a = num // 100
b = (num - a * 100) // 10
c = num % 10
if num == a**3 + b**3 + c**3:
print( num, "是水仙花數")
num += 1
執行結果:
153 是水仙花數
370 是水仙花數
371 是水仙花數
407 是水仙花數