Narcissus number refers to an n-bit positive integer (n>=3), and the sum of the n power of each number is equal to its own. For example: 153=1*1*1+5*5*5+3*3*3,153 is a three-digit number, and the sum of three times of each number is equal to 153. The Python language is used to find out the number of daffodils between 100~999.
Analysis process: The positive integer n of the single-digit 10-bit hundred are taken out, and then the sum of power; single-digit hundred better split, 10-bit words can be subtracted from the hundred and then divide the calculation.
1 #-*-coding:utf-8-*-2 #@Author: Fluttering _emmm3 Print("the number of daffodils between 100-999 is:")4 forAinchRange (100,999):#defines a number that is between 100-9995i = Int (a% 10)#Remove Bits6j = Int (a/100)#Take out the Hundred7k = Int ((a-j*100)/10)#10 bits are removed by calculation8 ifI**3 + j**3 + k**3 = = A:#The sum of the power of calculation, and the number itself to Judge9 Print(a)
Python basic exercise -003-to find all the daffodils between 100-999