我正在尝试使用 Coder 视图进行涉及反馈和多个条件语句的实验。你是怎么做到的?该任务最终将涉及 4 个数学问题,每个问题最多允许参与者尝试 3 次。结构应该是这样的......
循环 1:解决 4 个问题
循环 2:每个问题最多允许 3 次尝试
循环3:如果回答正确,则说“正确”并进入下一个问题;否则,说“不正确”并询问他们是否想再试一次或继续
这是我第一次使用 Python,我无法解决代码中的问题。没有返回错误消息,而是代码没有注册响应,因此任务被冻结在提示屏幕上。代码如下。我没有包括库和其他设置。
t=0
nProblem=4
nAttempt=3
while currentProb <= nProblem:
problemTimer.reset()
attempt = 1
# *prompt* updates
prompt.setAutoDraw(True)
prompt.setText(u'Problem prompt will go here.\n\nType in your answer and press enter to submit.', log=False)
while attempt <= nAttempt:
response = []
# *response* updates
core.wait(1) #LB - using this in place of that enormous if-statement
event.clearEvents(eventType='keyboard')
theseKeys = event.getKeys(keyList=['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0') in theseKeys: # subject responds with number value
response.append(theseKeys) # will tack on responses to previous responses
while event.getKeys(keyList=['return'])==[]:
# *timer* updates
if t <= 0.0:
# keep track of start time/frame for later
timer.setAutoDraw(True)
#elif timer.status == STARTED and t >= (0.0 + (600-win.monitorFramePeriod*0.75)): #most of one frame period left
#timer.setAutoDraw(False)
#if timer.status == STARTED: # only update if being drawn
timer.setText(str(round((600+routineTimer.getTime())/60,1)) , log=False)
# *minutesleft* updates
if t >= 0.0:
# keep track of start time/frame for later
minutesleft.setAutoDraw(True)
#elif minutesleft.status == STARTED and t >= (0.0 + (600-win.monitorFramePeriod*0.75)): #most of one frame period left
#minutesleft.setAutoDraw(False)
numberlist=event.getKeys(keyList=['1','2','3','4','5','6','7','8','9','0','backspace','return'])
for number in numberlist:
#if key isn't backspace, add key pressed to the string
if number !='backspace':
response.append(number)
#otherwise, take the last letter off the string
elif len(text)>=0:
response.remove(numberlist[number-1])
#continually redraw text onscreen until return pressed
answer = visual.TextStim(win, text=response,color="black",pos=(0,-100))
answer.draw()
win.flip()
event.clearEvents()
if len(theseKeys) > 0: # at least one key was pressed
response.keys.extend(theseKeys) # storing all keys
response.rt.append(response.clock.getTime())
#check for quit
if "escape" in theseKeys:
endExpNow = True
if response == '9999': # was this correct?
correctAns = 1
else:
correctAns = 0
if theseKeys == 'enter':
response.keys.extend(theseKeys) # storing all keys
response.rt.append(attemptresponse.clock.getTime())
if correctAns == 1:
attempt += 888 #ends and goes to next problem
currentProb += 1
dataFile.write(attempt,attemptresponse,theseKeys,response,correctAns) #output separated by commas
#dataFile.write('PID COND PROB ATT TIME RESP\n')
response_correct.draw()
win.flip()
event.waitKeys()
if correctAns == 0:
attempt += 1 #LB = was previously setting to 1 forever
dataFile.write(attempt-1,attemptresponse,theseKeys,response,correctAns) #output separated by commas
response_incorrect.draw()
win.flip()
theseKeys = event.getKeys(keyList=['q','space'])
if theseKeys == 'q':
continueRoutine = False
if theseKeys == 'space':
prompt.draw()
win.flip()
event.waitKeys()