[python practice questions] program 13

#Question : Print out all the "daffodils numbers", the so-called "daffodils numbers" refers to a three-digit number, and the sum of the cubes of the digits is equal to the number itself. For example: 153 is a "daffodil number", because 153=1 cube + 5 cube + 3 cube.

for i in range(100,1000):
    x = int(i / 100)
    y = int((i - x*100)/10)
    z = i - x*100 - y*10
     if i == ( x**3+y**3+z**3 ):
         print ( ' %s is the number of narcissus ' %i)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325028131&siteId=291194637