试图通过按顺序追加三个较小列表中的项来打印复合列表:
def final_xyz_lister():
global final_xyz_list
final_xyz_list = []
step=0
while step==0:
final_xyz_list.append(carbon_final_list[step])
final_xyz_list.append(oxygen_final_list[step])
final_xyz_list.append(hydrogen_final_list[step])
step=+1
while 0 < step < 50:
final_xyz_list.append(carbon_final_list[step])
final_xyz_list.append(oxygen_final_list[step])
final_xyz_list.append(hydrogen_final_list[step])
step=+1
else:
pass
如果我注释掉第二个while循环,列表的第一个元素将按预期打印在列表中,但是引入第二个while循环会导致内存错误
不需要在两个不同的while循环中附加这三个项。如果使用for循环,也会更简单。在这种情况下:
编辑:另外,我刚刚注意到错误,您使用了
step =+ 1
,这与说step = +1
或step = 1
是一样的。这就是为什么会出现内存错误,您一直将步骤定义为1,介于0和50之间,因此while循环一直在进行。你可能想写的是step += 1
,它一步一步地增加1,而不是设置为1相关问题 更多 >
编程相关推荐