刚刚上机课,老师居然让我们打印杨辉三角??
def yangHuiSanJiao(n):
#打印第一行和第二行
print("1".center(50))
next_line = [1,1]
second_line = ' '.join([str(i) for i in next_line])
print(second_line.center(50))
for i in range(2,n):
mid = []
for i in range(0, len(next_line)-1):
mid.append(next_line[i] + next_line[i+1])
next_line = [1] + mid + [1]
fin = ' '.join([str(i) for i in next_line])
print(fin.center(50))
yangHuiSanJiao(5)