0

I am making an experiment, and the participant must get the possibility to correct himself when he has given the wrong answer.

The goal is that the experiment goes on to the next trial when the correct answer is given. When the wrong answer is given, you get another chance.

For the moment, the experiment crashes after the first trial and it always waits for the second chance answer (even when the right answer was given).

Eva
  • 1
  • 1
  • When you say "the experiment crashes", presumably you get an error message? We need to know what that was. Additionally your code isn't complete enough for us to understand it. e.g. What is `x`? How does this `while` loop fit in your trial structure? Why are you using `waitKeys()` in conjunction with the `window.flip()` calls? `waitKeys()` will pause all drawing until a key is pressed, breaking the normal drawing cycle, and is probably something to avoid, in favour of checking `event.getKeys()` on every screen refresh. – Michael MacAskill Dec 26 '15 at 06:25

2 Answers2

0

You probably placed your Answerrunning = False at the wrong place. And probably you need to put break at the end of each branch. Please explain more what you want to do, I don't understand.

If you say you need to count tries, then I guess you should have something like number_of_tries = 0 and number_of_tries += 1 somewhere in your code.

Peret Finctor
  • 192
  • 1
  • 7
0

well, look like there were some code but that is no more so I don't know what was wrong with that, but by your description maybe you need something like this:

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")

this is fairly generic so you can define several tests reusing the given functions by just defining one like I did with my_test

Copperfield
  • 8,131
  • 3
  • 23
  • 29