def yanghui(n): l = [1] while True: yield l l = [1] + [l[x] + l[x + 1] for x in range(len(l) - 1)] + [1] if len(l) > n: break
m = yanghui(6) for i in m: print(i)
output: [1] [1, 1] [1, 2, 1] [1, 3, 3, 1] [1, 4, 6, 4, 1] [1, 5, 10, 10, 5, 1]
Sign in to make a reply
霁天13
def yanghui(n): l = [1] while True: yield l l = [1] + [l[x] + l[x + 1] for x in range(len(l) - 1)] + [1] if len(l) > n: break
m = yanghui(6) for i in m: print(i)
output: [1] [1, 1] [1, 2, 1] [1, 3, 3, 1] [1, 4, 6, 4, 1] [1, 5, 10, 10, 5, 1]