Python计算多个区间(多组)水仙花数
什么是水仙花数
水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153)
ls =[]
input1 = list(map(int,input().strip().split()))
while any(input1):
ls.append(input1)
input1 = list(map(int,input().strip().split()))
for i in range(len(ls)):
k = []
for j in range(ls[i][0],ls[i][1]+1):
if j == (j//100)**3+((j-(j//100)*100)//10)**3 + (j%10)**3:
k.append(j)
if any(k) == False:
print('no')
else:
for jj in range(len(k)-1):
print(k[jj],end=' ')
print(k[-1])
# j = 153
# print(j//100)
# print((j-(j//100)*100)//10)
# print(j%10)
计算结果:

作者:楚千羽
出处:https://www.cnblogs.com/chuqianyu/
本文来自博客园,本文作者:楚千羽,转载请注明原文链接:https://www.cnblogs.com/chuqianyu/p/16319674.html
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利!

浙公网安备 33010602011771号