利用Python 2.7打印杨辉三角

def triangle(n):

line = []

line1 = []

for i in range(n):

if i < 2:

line.append(1)

print line

else:

line1 = [1]

for k in range(i-1):

line1.append(line[k] + line[k+1])

line1.append(1)

print line1

line = line1

 

posted @ 2017-06-16 09:53  0苦夏0  阅读(219)  评论(0编辑  收藏  举报