The time limit :1.0s Memory limit :256.0MB
Yang Hui triangle is also called Pascal triangle , It's the first i+1 Line is (a+b)i The coefficients of the expansion of .
One of its important properties is : Each number in a triangle is the sum of the numbers on its shoulders .
The first part of Yang Hui's triangle is given below 4 That's ok :
1
1 1
1 2 1
1 3 3 1
give n, Output its front n That's ok .
The input contains a number n.
Output the front of Yang Hui triangle n That's ok . Each line starts with the first number of the line and outputs in turn , Use a space in the middle . Please don't output extra spaces in the front .
4
1
1 1
1 2 1
1 3 3 1
1 <= n <= 34.
n = int(input())
list=[[1]]
row=[]
for i in range(1,n):
row = []
row.append(1)
for m in range(1,i):
row.append(list[i-1][m-1]+list[i-1][m])
row.append(1)
list.append(row)
for a in range(n):
for b in range(a+1):
k=list[a][b]
print(k,end=' ')
print()
1. Input data type should be converted to int type
2. Clear the current row before writing each row of data
3. When making the display, we need to add one abscissa to the data length we need , You need to pay attention here range The range of a function is a closed before open interval .