1. What is the daffodil count?
A Narcissistic number, also known as a pluperfect digital invariant (PPDI), narcissistic number, self-power number, Armstrong number, or Armstrong number, is a 3-digit number in which the sum of the digits of each digit is equal to itself (e.g., 1^3 + 5^3 + 3^3 = 153), and the sum of the digits of each digit is equal to the sum of the digits of the other digit (e.g., 1^3 + 5^3 + 3^3 = 153). sum of the powers of 3 equals itself (e.g. 1^3 + 5^3+ 3^3 = 153)
See details:Daffodil Count - Baidu Encyclopedia
2. Realization.
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)] """ calculating a person、10、hundreds place (or column) in a decimal system x = int(num/100) # Hundreds y = int(num/10) % 10 # Ten digits z = num % 10 # Single digit split a = list(str(num)) a = list(map(eval, str(num))) """ if num == a[0] ** 3 + a[1] ** 3 + a[2] ** 3: (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('Wrong parameter type') else: raise Exception('Parameter out of range')
number_daffodils()
3、Lazy man method: list deduction type
a = [i * 100 + j * 10 + k for i in range(1, 10) for j in range(0, 10) for k in range(0, 10) if i * 100 + j * 10 + k == i ** 3 + j ** 3 + k ** 3] print(a)
to this article on the python implementation of the daffodil number of examples to explain this article, more related python implementation of the daffodil number of content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!