YouTip LogoYouTip

Python Exercise Example13

# Python2.x Python Exercise Instance 13 [![Image 3: Python 100 Examples](#) Python 100 Examples](#) **Question:** Print all "Narcissus numbers". A "Narcissus number" refers to a three-digit number whose sum of the cubes of its digits is equal to the number itself. For example: 153 is a "Narcissus number" because 153 = 1 cubed + 5 cubed + 3 cubed. **Program Analysis:** Use a for loop to control the numbers from 100 to 999, and decompose each number into its units, tens, and hundreds digits. Program source code: ## Instance(Python 2.0+) #!/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 **
← Python Exercise Example14Python Exercise Example12 β†’