python2 exercises - write a function to determine whether the number of daffodils

Narcissistic number (Narcissistic number) is also known as super does not fully digital variable (pluperfect digital invariant, PPDI), the number of narcissism, since a power of Armstrong Armstrong number or number (Armstrong number), refers to the number of daffodils a 3-bit number on each of the digital bit 3 is equal to the sum of power itself (eg: 5 + 1 ^ 3 ^ 3 ^ 3 + 3 = 153).

code show as below:

def func(n):
    if (n // 100) ** 3 + (n // 10 % 10) ** 3 + (n % 10) ** 3 == n and n > 100:
        print '%d是水仙花数' %n
    else:
        print '%d不是水仙花数' %n

print func(153)

Output effect

Here Insert Picture Description

We published 118 original articles · won praise 1402 · Views 210,000 +

Guess you like

Origin blog.csdn.net/weixin_45728976/article/details/105403239