用Python编写水仙花数

#找出水仙花数
def sxh(start, end):
    if end >= start and start >=100 and end<= 999:
        num=start #将num的值初始化
        L =[]
        while num<=end:
            x=num%10      #num取个位数
            y=num//10%10  #num取十位数
            z=num//100    #num取百位数
            if (num==pow(x,3)+pow(y,3)+pow(z,3)):
                L.append(num) #将num放在一个列表里
            num=num+1
        return L   #返回列表
print(sxh(100,999))
原文地址:https://www.cnblogs.com/lengjf/p/9819694.html