在循环中休息并等待人继续

Having a break within a loop and waiting for the person to continue

大家好,我是 运行 一个有 120 次试验的实验。我想每 30 次试验在循环中添加一个中断,并等待参与者在准备好继续时按下一个键。我的循环代码如下所示

start.draw()
win.flip()
event.waitKeys(keyList=['return'])

win.flip()

cross.draw()
win.flip()
event.waitKeys(keyList=['5'])


for stim in stroop:
    colour.text = stim[0]
    colour.color = stim[1]
    colour.draw()
    display_time = win.flip()

如何在此 for 循环中添加中断? 谢谢!!

您可以使用枚举来跟踪迭代次数:

for idx, stim in enumerate(stroop):
    # The +1 makes it so we avoid asking the user's input on first iteration.
    if (idx + 1) % 30 == 0:
        event.waitKeys(keyList=['return'])
    [...]

对了,python中的breaks指的是跳出循环。你想要做的是 "wait for user input".