Python basic exercise -003-to find all the daffodils between 100-999

Source: Internet
Author: User

Narcissus number refers to an n-bit positive integer (n>=3), and the sum of the n power of each number is equal to its own. For example: 153=1*1*1+5*5*5+3*3*3,153 is a three-digit number, and the sum of three times of each number is equal to 153. The Python language is used to find out the number of daffodils between 100~999.

Analysis process: The positive integer n of the single-digit 10-bit hundred are taken out, and then the sum of power; single-digit hundred better split, 10-bit words can be subtracted from the hundred and then divide the calculation.

1 #-*-coding:utf-8-*-2 #@Author: Fluttering _emmm3 Print("the number of daffodils between 100-999 is:")4  forAinchRange (100,999):#defines a number that is between 100-9995i = Int (a% 10)#Remove Bits6j = Int (a/100)#Take out the Hundred7k = Int ((a-j*100)/10)#10 bits are removed by calculation8     ifI**3 + j**3 + k**3 = = A:#The sum of the power of calculation, and the number itself to Judge9         Print(a)

Python basic exercise -003-to find all the daffodils between 100-999

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.