Feedback for answers in the wrong order doesn't work: '<' not supported between instances of 'float' and 'list'

Hello! I’m trying to create a dual task experiment with the following feedbacks:

  1. ‘Too slow’ when no answer is given
  2. ‘Correct’ when both answers are correct and in the right order
  3. ‘Wrong’ when a wrong answer is given
  4. ‘Wrong order’ when task 2 is answered before task 1

I had no problem with programming feedback 1) to 3). But when I wanted to consider the order of the answers too everything went wrong.

This code is what I’m currently trying to work with:

if key_resp_t2.rt < key_resp_t1.rt:
    msg = 'Wrong order'
elif key_resp_t1.keys == None or key_resp_t2.keys == None:
    msg = 'Too slow'
elif key_resp_t1.corr and key_resp_t2.corr:
    msg = 'Right'        
else:
    msg = 'Wrong'

My error message is: TypeError: '<' not supported between instances of 'float' and 'list'

I only store the last key for each of both keyboard components (key_resp_t1 and key_resp_t2). I placed the code at ‘Begin routine’.

Any ideas of what I did wrong?

Thank you!

Hello hellopsych

AFAIK, you can’t or you shouldn’t have two keyboard-components in one routine.

You could use one keyboard-component, check whether two keypresses have taken place, end the routine, and finally check for the proper order of the answers and the number of responses given.

See here for a similar problem

Best wishes Jens

1 Like

Hello everbody. I think I solved the problem:

  • First of all, I changed my settings so that I store all of the entered keyboard responses and not just the last one. I still don’t know why my original code didn’t work. Weird. I would still appreciate suggestions about why this happened.
  • Now I get a list with keyboard inputs (that is where the len is). I have to change my code so that there will be also a feedback when too many keys are pressed (otherwise the participants could just press every key all the time to get the right answer)
  • For the right or wrong order I compared the last entered key (that’s where the [-1] is)
if ( \
        key_resp_t1.keys is None \
        and len(key_resp_t2.rt) > 0
    ) or ( \
        len(key_resp_t1.rt) > 0 \
        and len(key_resp_t2.rt) > 0 \
        and key_resp_t2.rt[-1] < key_resp_t1.rt[-1] \
    ):
    msg = 'Wrong order'
elif key_resp_t1.keys is None \
    or key_resp_t2.keys is None:
    msg = 'Too slow'
elif len(key_resp_t1.keys) > 1 \
    or len(key_resp_t2.keys) > 1:
    msg = 'Too many keys were pressed'
elif key_resp_t1.keys == [t1_resp_corr] \
    and key_resp_t2.keys == [t2_resp_corr]:
    msg = 'Right'
else:
    msg = 'Wrong'

Thanks for letting me know. After spending literal hours on my code I could make it work with two keyboard components. However, this was such a pita. I will restart the project and try to program it with just one keyboard component. After all, this was just an exercise to learn PsychoPy and I want to learn it the right way and not the wrong and complicated way.