首页 > 编程语言 > 详细

【Python/转】杨辉三角/帕斯卡三角

时间:2020-05-30 19:44:48      阅读:35      评论:0      收藏:0      [点我收藏+]
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
‘‘‘

重点:

  1. 如何将杨辉三角的性质(肩上两数字之和)应用起来?
  2. 如何排版出金字塔形?
  3. 末尾的1!

【Python/转】杨辉三角/帕斯卡三角

原文:https://www.cnblogs.com/coder106/p/12993850.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!