Discuss / Python / 根据SICP练习1.12 思路写的~~

根据SICP练习1.12 思路写的~~

Topic source

RetaMia

#1 Created at ... [Delete] [Delete and Lock User]
在此插入代码

def pascal_element(x, y): if x == 0: return 1 elif x == y: return 1 else: return pascal_element(x-1, y-1) + pascal_element(x, y-1)

def pascal_line(line): l = [pascal_element(x, line-1) for x in range(line)] return l

def triangles(): n = 1 while(True): line = pascal_line(n) yield line n = n + 1


  • 1

Reply