Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

357
Visualizações
If/else statement is not working properly in OpenSesame as expected

I am using python-based OpenSesame for building an experiment. The whole experiment is working fine except for one thing. I wrote an inline python script to give conditional auditory feedback to the participants. In the first condition, the 'Sound_Win.wav' feedback should occur if the sum of 2 variables is more than 0 (working fine). In the second condition, the 'Sound_Lose.wav' feedback should occur if the sum of 2 variables is less than 0 (working fine). In the third condition, the 'Sound_No.wav' feedback should occur if the sum of 2 variables is equal to 0. However, using the following code, the third condition is playing 'Sound_Lose.wav' feedback instead of 'Sound_No.wav' feedback (error). Any help would be highly appreciated.

if [loss]+[win] > 0:
    src = pool['Sound_Win.wav']
    my_sampler = Sampler(src, volume=1.0)
    my_sampler.play()
           
if [loss]+[win] < 0:
    src = pool['Sound_Lose.wav']
    my_sampler = Sampler(src, volume=1.0)
    my_sampler.play()

elif [loss]+[win] = 0:
    src = pool['Sound_No.wav']
    my_sampler = Sampler(src, volume=1.0)
    my_sampler.play()
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

From what I am understand from the code , instead of writing the second if , from the starting , press a tab to indent it inside the first if statement and then write the elif statement as per the second if statement , because the second one only happen if the first one goes incorrect or wrong !!

If I understood it wrong , then please do let me know !! I'll surely look forward into it !!

Thanks 😊

about 4 years ago · Juan Pablo Isaza Relatório

0

If I understand you correctly then loss and win are simply integers, so your code should be:

if loss + win > 0:
    src = pool['Sound_Win.wav']
    my_sampler = Sampler(src, volume=1.0)
    my_sampler.play()
           
elif loss + win < 0:
    src = pool['Sound_Lose.wav']
    my_sampler = Sampler(src, volume=1.0)
    my_sampler.play()

else:
    src = pool['Sound_No.wav']
    my_sampler = Sampler(src, volume=1.0)
    my_sampler.play()

You simply add together loss and win. Also since integers are very closely defined, then using an if/elif/else chain like this covers all the possibilities.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda