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!