凌波仙子数(Narcissistic number)也被称为超完所有字静止数(pluperfect digital invariant, PPDI)、自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),凌波仙子数是指一个 3 位数,它的每个位上的数字的 3次幂之和即是它自己(比方:1^3 + 5^3+ 3^3 = 153)

def number_daffodils(m=100, n=1000):

if type(m) is int and type(n) is int and 100 <= m < n <= 1000:

daffodils = []

for num in range(m, n):

a = [int(s) for s in str(num)]

"""

计划个、十、百位数

x = int(num/100) # 百位数

y = int(num/10) % 10 # 十位数

z = num % 10 # 个位数

将平头按位拆分

a = list(str(num))

a = list(map(eval, str(num)))

"""

if num == a[0] ** 3 + a[1] ** 3 + a[2] ** 3:

daffodils.append(num)

if len(daffodils) == 0:

print("No number of daffodils")

else:

print(" ".join(str(i) for i in daffodils))

elif type(m) is not int or type(n) is not int:

raise Exception('参数典型缺点')

else:

raise Exception('参数胜过范畴')

number_daffodils()

输入截止为153 370 371 407