杨辉三角
2017-12-14 本文已影响0人
Modelstrategy
def pascal_triangle(n):
if n == 1:
return [ 1 ]
elif n == 2:
return [1, 1]
else:
list = []
list.append(1)
for i in range(1, n-1):
list.append(pascal_triangle(n-1)[i-1] + pascal_triangle(n-1)[i])
list.append(1)
return list
print(pascal_triangle(9))
for i in range(9):
print(pascal_triangle(i))