用Python求出所有的三位水仙花数,感谢(财富可追加)
发布网友
发布时间:2022-04-07 04:58
我来回答
共3个回答
热心网友
时间:2022-04-07 06:27
for i in range(100, 1000):
a, b, c = (int(s) for s in str(i))
if i == a ** 3 + b ** 3 + c ** 3:
print(i)
# or
for i in range(100, 1000):
if i == sum(int(s) ** 3 for s in str(i)):
print(i)
热心网友
时间:2022-04-07 07:45
import math
for i in range(100, 1000):
x = math.floor(i/100)
y = math.floor((i - x*100)/10)
z = i - math.floor(i/10) *10
if i == x**3 + y**3 + z**3:
print(i, end=', ')
热心网友
时间:2022-04-07 09:20
for i in range(100, 1000):
if i == sum(map(lambda x: int(x)**3, str(i))):
print(i)