Discuss / Python / 我的很奇怪,结果对的,可是测试失败,为什么呢 求助

我的很奇怪,结果对的,可是测试失败,为什么呢 求助

Topic source

余智聪f

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

ef triangles(): m=[1] yield m m.append(1) yield m s=[1,1] while True: m=[1] for i in range(len(s)-1): m.append(s[i]+s[i+1]) m.append(1) s=m yield m n=0 results=[] for t in triangles(): print(t) results.append(t) n=n+1 if n==10: break print('results=',results) if results==[ [1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 126, 84, 36, 9, 1] ]: print('测试通过!') else: print('测试失败!')

余智聪f

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

那个第一个d没印上去,结果分析reults 第一个元素是【1,1】,【1,1】,【1,2,1】.... 为什么第一个是【1,1】而print(t)确实正常的【1】


  • 1

Reply