How to write Python daffodil number programming code

angryTom
Release: 2020-03-03 13:46:55
Original
46716 people have browsed it

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

Program output:

153
370
371
407
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template