#-*- 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)
杨辉三角
最新推荐文章于 2023-08-12 17:41:26 发布