#!/usr/bin/env python3
'''
打印杨辉三角
'''
def triangle():
yield [1]
yield [1, 1]
upline = [1, 1]
count = 0
while True:
count += 1
line = [1]
for x in range(count):
line.append(upline[x] + upline[x + 1])
line.append(1)
yield line
upline = line
if __name__ == '__main__':
yang = triangle()
for x in range(10):
print(next(yang))
yang = triangle()
row = 6
width = 2
for x in range(row):
l = [ str(e).center(width) for e in next(yang)]
print(''.join(l).center(row * width))
来源:CSDN
作者:qq_41572664
链接:https://blog.csdn.net/qq_41572664/article/details/104573521