Python print Yang Hui triangle

Source: Internet
Author: User

Yang Hui Triangle, is a geometric arrangement of two-term coefficients in triangles

    1. Each number equals two of the sum above it.
    2. Each line of numbers is symmetrical, starting from 1 to become larger.
    3. The number of the nth row has n items.
    4. The nth row number and 2n-1.
    5. The number of m in the nth row can be expressed as C (n-1,m-1), which is the number of combinations of m-1 elements taken from n-1 different elements.
    6. The number of the nth row is equal to the number of n-m+1 and is one of the combinatorial number properties.
    7. Each number equals the sum of the left and right two digits of the previous line. This property can be used to write out the entire Yang Hui triangle. That is, the number of n+1 in line I is equal to the sum of the number of i-1 and the number of the first n rows, which is also one of the properties of the combinatorial number. That is, C (n+1,i) =c (n,i) +c (n,i-1).
    8. (A+B) The coefficients in the expansion of n correspond to each of the n+1 lines in the Yang Hui triangle in turn.

Property 5 and Property 7 are the basic properties of Yang Hui Triangle, and are the basis of studying other laws of Yang Hui Triangle.

1Num=input ('Please enter the number of lines:')2num =int (num)3 4List1 =[]#list is used to save the Yang Hui triangle5  forNinchrange (num):6Row =[1]#Save Row7 list1.append (Row)8 9     ifn = =0:Ten         Print(Row) One         Continue A      forMinchRange (1, N): -Row.append (List1[n-1][m-1] + list1[n-1][m]) -Row.append (1) the  -     Print(ROW)

Python print Yang Hui triangle

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.