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)

计算结果:

image

posted @ 2022-05-28 00:41  楚千羽  阅读(93)  评论(0编辑  收藏  举报