Discuss / Python / 作业打卡

作业打卡

Topic source

石年80059

#1 Created at ... [Delete] [Delete and Lock User]
def yanghui(max):    n , b = 1 , [1]    while n <= max:        yield b        a, b, i = b, [1], 1        while i <= n :            if i < len(a):                b.append(a[i-1]+a[i])            else:                b.append(1)            i += 1        # yield b        n += 1d = yanghui(5)# next(d)while True:    try:        x = next(d)        print('d:',x)    except StopIteration as e:        print('dafaf:',e.value)

能正常print()  ,但是改成yield 就永远都是[1],这是为什么?

石年80059

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

怎么贴代码才不会乱


  • 1

Reply