def createL(l): # 生成杨辉三角的一行 L = [1] for x in range(1, len(l)): L.append(l[x] + l[x-1]) L.append(1) return L def printL(L, W): # 打印 s = "" for x in L: s += str(x) + " " print(s.center(W)) L = [1] row = int(input("输入行数:")) width = row * 4 # 设置打印宽度 for x in range(row): printL(L, width) L = createL(L)
‘‘‘
版权声明:本文为CSDN博主「庄AC」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zyz1431/article/details/79104035
‘‘‘
重点:
原文:https://www.cnblogs.com/coder106/p/12993850.html