这是一个计算水仙花数的Python代码:
for num in range(100, 1000): temp = num sum = 0 while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 if num == sum: print(num)
这是一个计算水仙花数的Python代码:
for num in range(100, 1000): temp = num sum = 0 while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 if num == sum: print(num)