How to find the number of daffodils in Python?

青灯夜游
Release: 2020-05-16 18:03:24
Original
15197 people have browsed it

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)
Copy after login

The output result of the above example is:

153 370 371 407
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!