问题描述
出于某种原因,当 event.getKeys() 在下面的第 5 行中运行时,它会立即转到屏幕上显示的下一个刺激,而无需使用下面的所有代码来帮助决定接下来显示哪个刺激。 但是,发生的事情是代码正在运行,但在它呈现下一个刺激之后。所以基本上这是一个逐个错误,因为每个“下一个刺激”都使用来自上一个刺激选择的数据。 我试图将所有这些都包装在一个 while 循环中,但它仍然不起作用。 所以,假设有人按“2”让一张快乐的脸出现。然后下一次审判他们按“7”以获得一张悲伤的脸。当他们按下那个 7 时,它会显示一张笑脸,因为这是之前的输入键 (2) 选择。然后,无论他们接下来选择什么,总会有一张悲伤的脸,因为之前按了 7。在继续下一个呈现的刺激之前,所有代码都没有运行。 感谢您的帮助。
# random numbers for choosing a picture and Happy/Sad
rand = random.randint(1,140)
# acquire response key for bias
key = str(event.getKeys())
# check is bias direction equals key selection
if bias == key:
print ("choosing H or S")
# get happy/sad for bias
biasPercent = random.random() # check for 90/10%
if biasPercent <= 0.90:
biasEmotion = "S"
if biasPercent > 0.90:
biasEmotion = "H"
print ("..................biasEmotion = " + biasEmotion)
if bias != key:
print ("choosing H or S")
# get happy/sad for bias
biasPercent = random.random() # check for 90/10%
if biasPercent <= 0.90:
biasEmotion = "H"
happyFaceCount = happyFaceCount + 1
if biasPercent > 0.90:
biasEmotion = "S"
sadFaceCount = sadFaceCount + 1
print ("..................biasEmotion = " + biasEmotion)
comparison = False
iteration = 1
# chooses a random face from excel column A
while (imgName in listOfFacesHappy) or (imgName in listOfFacesSad) or comparison:
print (str(iteration) + " iteration")
iteration = iteration + 1
rand = random.randint(1,140)
face = insheet.row_values(rand)
imgName = face[0] # Column A (index 0) from excel
sexIndex = imgName[1] # second char in name of file
emotionIndex = imgName[4] # fifth char in name of file
if (biasEmotion != emotionIndex):
print ("emotions not equal")
comparison = True
else:
print ("..............found emotion")
comparison = False
if emotionIndex == "H":
listOfFacesHappy.append(imgName)
happyFaceCount = happyFaceCount + 1
if emotionIndex == "S":
listOfFacesSad.append(imgName)
sadFaceCount = sadFaceCount + 1
#print ("face list = " + str(listOfFaces))
# names currently hardcoded and not taken from excel or text file yet
if sexIndex == "F":
nameR = random.choice(fnames)
nameL = random.choice(fnames)
while nameL == nameR: #make sure two names are different
nameR = random.choice(fnames)
if sexIndex == "M":
nameR = random.choice(mnames)
nameL = random.choice(mnames)
while nameL == nameR: #make sure two names are different
nameR = random.choice(mnames)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)