python练习2 计算100-999之间的水仙花数
2016-06-17 21:48
573 查看
如果一个 3 位数等于其各位数字的立方和,则称这个数为水仙花数。例如:153 = 1^3 + 5^3 + 3^3,因此 153 就是一个水仙花数,求100~999之间的水仙花数
我的答案1
我的答案2
for i in range(100,1000):
a = i//100
b = (i-a*100)//10
c = i-a*100-b*10
if i == a**3 +b**3 +c**3:
print(i)
i=i+1
else:
i=i+1
我的答案1
#!/usr/bin/python # -*- coding: UTF-8 -*- for a in range(100,1000): x = int(str(a)[0]) y = int(str(a)[1]) z = int(str(a)[2]) if a == (x**3 +y **3 +z **3): print a,"是水仙花数"
我的答案2
for i in range(100,1000):
a = i//100
b = (i-a*100)//10
c = i-a*100-b*10
if i == a**3 +b**3 +c**3:
print(i)
i=i+1
else:
i=i+1
相关文章推荐
- Python图像处理库:Pillow 初级教程
- python基础
- PYTHON-基础-时间日期处理小结
- Python 小练习_计数器
- windows下搭建eclipse关于python的开发环境及初始化参数配置
- windows下搭建eclipse关于python的开发环境及初始化参数配置
- Python中的Iterables, Iterator, Generators, Yield
- python常用模块
- python的内建函数详解
- 38. Count and Say [easy] (Python)
- python 多文件列相加
- python之删除30天以前的文件
- 【翻译】Tweepy 3.5.0 Doc (4) Cursor Tutorial
- 58. Length of Last Word [easy] (Python)
- python学习7
- [python] 关于错误 ImportError: cannot import name compile_command
- path-sum python java
- python 收音机
- python IDLE 背景以及字体的修改
- 把玩之python爬虫正则表达式