查找100-999之間的水仙花數

水仙花數,即一個三位數的個,十,百三位數字的立方和等於該三位數。app

 1 from math import pow
 2 
 3 if __name__ == "__main__":
 4     
 5     l = list()
 6     for x in range(100, 1000):
 7         x1, x2, x3 = str(x)
 8         if pow(int(x1), 3) + pow(int(x2), 3) + pow(int(x3), 3) == x:
 9             l.append(x)
10     print(l)
相關文章
相關標籤/搜索