author = 'FTY'
#输出杨辉三角前x项
def triangles(x): L= [1,1] n = 1 x==1 yield [1] while n<x: yield L L = [L[i] + L[i+1] for i in range(n)] L.insert(0, 1) L.append(1) n = n + 1 return 'done' r = triangles(x)#输入x for i in r: print(i)
Sign in to make a reply
用户8938128506
-- coding: utf-8 --
author = 'FTY'
#输出杨辉三角前x项
def triangles(x): L= [1,1] n = 1 x==1 yield [1] while n<x: yield L L = [L[i] + L[i+1] for i in range(n)] L.insert(0, 1) L.append(1) n = n + 1 return 'done' r = triangles(x)#输入x for i in r: print(i)