Python:如何为参与者提供答案的可能性

Python:如何为参与者提供答案的可能性,python,while-loop,psychopy,Python,While Loop,Psychopy,我正在做一个实验,参与者必须有可能在给出错误答案时纠正自己 我们的目标是,当给出正确答案时,实验继续进行到下一次试验。当给出错误的答案时,你会有另一次机会 目前,实验在第一次试验后崩溃,它总是等待第二次机会的答案(即使给出了正确的答案) 您可能将您的答案running=False放错了位置。可能您需要在每个分支的末尾放置break。请多解释一下你想做什么,我不明白 如果你说你需要计算尝试次数,那么我想你应该在你的代码中有一些类似于尝试次数=0和尝试次数+=1的东西。好吧,看起来好像有一些代码,但

我正在做一个实验,参与者必须有可能在给出错误答案时纠正自己

我们的目标是,当给出正确答案时,实验继续进行到下一次试验。当给出错误的答案时,你会有另一次机会


目前,实验在第一次试验后崩溃,它总是等待第二次机会的答案(即使给出了正确的答案)

您可能将您的
答案running=False
放错了位置。可能您需要在每个分支的末尾放置
break
。请多解释一下你想做什么,我不明白


如果你说你需要计算尝试次数,那么我想你应该在你的代码中有一些类似于
尝试次数=0
尝试次数+=1
的东西。

好吧,看起来好像有一些代码,但这已经不多了,所以我不知道这有什么问题,但根据你的描述,也许你需要这样的东西:

def ask_user(question,answer):
    """ask the user some question and return if the expected answer was given """
    return answer == input(question)

def trial(question,answer,chances=3):
    """repeatedly ask the user a question by a number of chances and return True
       if the expected answer is given, otherwise return False"""
    for i in reversed( range(chances) ):
        if ask_user(question,answer):
            return True
        else:
            print("wrong answer you have",i,"more chances")
    return False

def test(trials,chances=3):
    """given a list of tuples of the form (question,answer) ask the user for
       an answer to each question given him/her a number of chances in each 
       one and return True if all of them are answered correctly otherwise 
       return False at the first failure """
    print("Welcome to this test, please answer the next few questions:")
    for i,(q,a) in enumerate(trials,1):
        print("questions #",i)
        if not trial(q,a,chances):
            return False
    return True

def my_test():
    my_trials=[("1+2= ","3"),
           ("translate 'home' to Spanish: ","casa"),
           ("what is the Answer to the Meaning of Life, the Universe, and Everything Else: ","42")
           ]
    print("you pass the test" if test(my_trials) else "You fail this test")
这是相当通用的,因此您可以定义几个重用给定函数的测试,只需定义一个,就像我在
my_test

中所做的那样,当您说“实验崩溃”时,您可能会收到一条错误消息?我们需要知道那是什么。此外,您的代码不够完整,我们无法理解。e、 什么是
x
?这个
while
循环如何适合您的试用结构?为什么要将
waitKeys()
window.flip()调用结合使用
waitKeys()
将暂停所有绘图,直到按下一个键,从而打破正常的绘图周期,这可能是需要避免的,在每次屏幕刷新时检查
event.getKeys()