Adding elif to code component generates Python syntax error

If this template helps then use it. If not then just delete and start from scratch.

Psychopy 2021.2.3 on Catalina

Hi - why am I getting Python JS errors when I try and insert an elif component to a working if/then loop?

THIS WORKS
if key_resp_3.corr:
msg=“Good!”
Col=“green”
Posit=[0,7]
else:
msg=“WRONG”
Col=“red”
Posit=[0,-7]

THIS DOESN’T -“Syntax error : Fix Python code” regardless of indentation.
if key_resp_3.corr:
msg=“Good!”
Col=“green”
Posit=[0,7]
elif
else:
msg=“WRONG”
Col=“red”
Posit=[0,-7]

what am I doing wrong?! thanks!

Hello,
You typed:

elif
else:

You can either use elif: or else:; you cannot use both of them one after the other without any statements in them. Also, your elif: doesn’t include a colon.

Why did you insert this elif? What are you trying to do? If you want to use elif instead of else, you need to include a condition.

Thanks,
Chen

Hi yes I know - I stopped after typing elif as it gave an error. maybe that was my mistake -it works in another programme. also how can I delete queries? I tried to delete this one when I discovered it was working elsewhere, but couldn’t see how to…

Hey,

This is not a valid Python syntax, I don’t see how it can work on another program using Python. If you want to use elif, you need to include a condition. You cannot have empty statements.
What do you mean by saying you want to delete the query?

Chen

as I said - I know you need conditions after elif or if; but I stopped editing when it gave an error.

by deleting queries I meant this question! I wanted to when I found it was working elsewhere… (and didn’t want to waste people’s time)

Hey,
I don’t quite understand what you are trying to do. You want to include an elif statement, but you know how it works, so where is the problem?
My confusion comes from the word query, which doesn’t refer to something in your code.
Where did you see it working? Maybe it will help me understand your intention better.

Oh, you want to delete the post, I thought it had something to do with data, lol.

No, query refers to this post! I can’t see how to delete it. and the problem was that the second I wrote elif it stated it was a python error. I think now that’s because I hadn’t yet added the rest of the statements.

Yes! Delete this post!

It’s just that the word query regarding code gets a different meaning in my vocabulary, haha.
Sorry about it :slight_smile: