def triangles(): line = [1] while True: yield line line = [line[x] + line[x+1] for x in range(len(line)-1)] line.append(1) line.insert(0,1)
line = [line[x] + line[x+1] for x in range(len(line)-1)] 这一行中进行第二行的循环时 len(line)-1=0 此时line[x+1]不应该不存在么
Sign in to make a reply
Wizard92334
def triangles(): line = [1] while True: yield line line = [line[x] + line[x+1] for x in range(len(line)-1)] line.append(1) line.insert(0,1)