水仙花数,即一个三位数的个,十,百三位数字的立方和等于该三位数。
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)
水仙花数,即一个三位数的个,十,百三位数字的立方和等于该三位数。
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)
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。