杨辉三角
程序员文章站
2024-01-16 10:35:22
...
#-*- coding:utf-8 -*-
def triangles(n):
list1=[1]
list2=[1,1]
yield list1
yield list2
temp=1
now=3
list1=list2
list2=[1]
while now <= n:
while temp < now-1:
list2.append(list1[temp]+list1[temp-1])
temp=temp + 1
list2.append(1)
list1=list2
now=now + 1
yield list2
list2=[1]
temp=1
for list_temp in triangles(10):
print(list_temp)