首页 热点专区 小学知识 中学知识 出国留学 考研考公
您的当前位置:首页正文

杨辉三角

2024-12-07 来源:要发发知识网

使用python

代码为

l = [1] while True: yield l l.append(0) l = [l[i]+l[i-1] for i in range(len(l))]


输出结果

[1] [1, 1] [1, 2, 1] [1, 3, 3, 1] [1, 4, 6, 4, 1] [1, 5, 10, 10, 5, 1] [1, 6, 15, 20, 15, 6, 1] [1, 7, 21, 35, 35, 21, 7, 1] [1, 8, 28, 56, 70, 56, 28, 8, 1] [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]

显示全文