Discuss / Python / exercise(generator)

exercise(generator)

Topic source

叫我_小军

#1 Created at ... [Delete] [Delete and Lock User]

自己花了挺长时间在思考者个提上,用的方法比较简单,结果还是比较满意,有小小成就感。过程中会觉得有点有困难,但是逻辑思路、语法弄清楚,其实也没有想象中的那么难。 看了评论里面的大神,作为编程小白的我瑟瑟发发,要膜拜膜拜大神们。

def triangles(max): if True: yield [1] a,n = [1,1],2 while n <= max: yield [1] + [a[b] + a[b + 1] for b in range(n - 2)] + [1] a = [1] + [a[b] + a[b + 1] for b in range(n - 2)] + [1] n = n + 1

for t in triangles(10): print(t)

为什么要写

if True。

语句呢?


  • 1

Reply