九州体育网 - 十年信誉网站

关于作者

Discuss / Python / 为啥测试失败呢?怎么改啊

为啥测试失败呢?怎么改啊

Topic source

无中生有unknown

#1 Created at ...

-- coding: utf-8 --

def triangles(): p,a,b=0,[],[1] while p<10: yield b a=b[:] a.insert(0,0) b.append(0) b=[m+n for m,n in zip(a,b)]

无中生有unknown

#2 Created at ...

和下面有人提到的yield中断机制有关,输出的result会带上0,增加一个变量即可: -- coding: utf-8 --

def triangles(): a,b=[],[1] while True: c=b[:] yield c a=b[:] a.insert(0,0) b.append(0) b=[m+n for m,n in zip(a,b)]


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.