查找100-999之间的水仙花数

水仙花数,即一个三位数的个,十,百三位数字的立方和等于该三位数。

 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)

 

posted @ 2020-12-01 19:29  琵琶真的行  阅读(814)  评论(0编辑  收藏  举报