Home>Article>Backend Development> How to find the number of daffodils in Python?

How to find the number of daffodils in Python?

青灯夜游
青灯夜游 Original
2020-04-21 16:38:55 15226browse

How to find the number of daffodils in Python?

The Narcissistic number is also known as the pluperfect digital invariant (PPDI), narcissistic number, autoexponential number, Armstrong number or Armstrong number (Armstrong number), Daffodil number refers to a 3-digit number, the sum of the third power of the digits in each digit is equal to itself.

Simply put: If a 3-digit number is equal to the sum of the cubes of its digits, then this number is called a narcissus number.

For example: 153 = 1^3 5^3 3^3, so 153 is a narcissus number

Program analysis: Use for loop to control 100-1000 numbers, and decompose each number Out of the ones, tens, hundreds.

Program source code:

for i in range(100,1000): a = i//100 b = (i-a*100)//10 c = (i-a*100-b*10) if i == pow(a,3)+pow(b,3)+pow(c,3): print(i)

The output result of the above example is:

153 370 371 407

Recommended learning:Python video tutorial

The above is the detailed content of How to find the number of daffodils in Python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn