如何使用 Python 在区间内查找阿姆斯特朗数?
pythonserver side programmingprogramming更新于 2025/7/15 9:16:17
如果数字中各个数字的立方和等于数字本身,则称为阿姆斯特朗数。例如 153=1**3+5**3+3**3
示例
以下 Python 程序查找 100 到 1000 之间的阿姆斯特朗数
for num in range(100,1000): temp=num sum=0 while temp>0: digit=temp%10 sum=sum+digit**3 temp=temp//10 if sum==num: print (num)
输出
输出如下 −
153 370 371 407
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

