Latest web development tutorials

Python includes exercises 13

Python 100 Li Python 100 Li

Topic: Print out all the "narcissistic number", called "narcissistic number" refers to a three-digit number, which you figures Cube and equal to the number itself. For example: 153 is a "narcissistic number" because 153 = 1 cubic cubic +5 +3 cubed.

Program analysis: the use of the control loop for the number of 100-999, each factorization of bits, ten, one hundred.

Source Code:

#!/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

The above example output is:

153
370
371
407

Python 100 Li Python 100 Li