Python implements Narcissus number

Source: Internet
Author: User
Narcissus numbers (narcissistic number) are also known as ultra-complete numeric invariants (pluperfect digital invariant, ppdi), narcissism, self-power, Armstrong or Armstrong numbers (Armstrong number), Narcissus number refers to an n-bit number (n≥3), the sum of the n power of the number on each bit of it is equal to itself (for example: 1^3 + 5^3+ 3^3 = 153) "From Baidu Encyclopedia."

The following gives the three-digit daffodil Python code implementation:

# 循环遍历出所有三位数for tmp in range(100, 1000):    # 取余找出个位数    a = tmp % 10    # 求商取整找出百位数    b = int(tmp / 100)    # 通过求商取整找出百位和十位,然后求商找出十位    c = int(tmp / 10) % 10    if tmp == a**3 + b**3 + c**3:        print("%d" %tmp)

Interested in Baidu Encyclopedia to understand the following

Python implements Narcissus number

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.