хорошо, посмотрите, как там были некоторые код, но это не более, так что я не знаю, что случилось с этим, но по вашему описанию, может быть, вам нужно что-то вроде этого:
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")
это довольно generic, так что вы можете определить несколько тестов, повторно использующих заданные функции, просто определяя один, как я сделал с my_test
Когда вы говорите «сбой в эксперименте», предположительно вы получите сообщение об ошибке? Нам нужно знать, что это было. Кроме того, ваш код недостаточно для понимания. например Что такое 'x'? Как этот цикл 'while' подходит для вашей пробной структуры? Почему вы используете 'waitKeys()' в сочетании с вызовами 'window.flip()'? 'waitKeys()' приостанавливает весь чертеж до тех пор, пока не будет нажата клавиша, не будет нарушена нормальный цикл рисования и, вероятно, что-то избежать, в пользу проверки 'event.getKeys()' на каждом обновлении экрана. –