Home >Backend Development >Python Tutorial >How to write Python daffodil number programming code

How to write Python daffodil number programming code

angryTom
angryTomOriginal
2020-03-03 13:46:5546768browse

How to write Python daffodil number programming code

How to write Python daffodil number programming code

Daffodil number definition

Mathematics There is a narcissus number, which is defined as follows: "Darcissus number" refers to a three-digit number, the sum of the cubes of its digits is equal to itself, for example:

153=1^3 5^ 3 3^3.

Recommended learning: Python video tutorial

So how to use Python to find the number of all daffodils?

Use python to find the number of all daffodils within 1000

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)

Program output:

153
370
371
407

For morepython tutorial, please Follow PHP Chinese website!

The above is the detailed content of How to write Python daffodil number programming code. 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