Python 练习实例43

版权声明:版权所有,转载请注明链接! https://blog.csdn.net/qq_43558971/article/details/91357797

https://www.runoob.com/python/python-exercise-example13.html
题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
for n in range(100,1000):
    i = n / 100
    j = n / 10 % 10
    k = n % 10
    if n == i ** 3 + j ** 3 + k ** 3:
        print n

猜你喜欢

转载自blog.csdn.net/qq_43558971/article/details/91357797
今日推荐