Else statement executing even the IF statement is TRUE

后端 未结 4 1718
醉酒成梦
醉酒成梦 2021-01-23 17:55

I have a problem in Python language that is described in a title.

 for slovo in slova:
        if pygame.mouse.get_pressed()[0] and slovo[\"rect         


        
4条回答
  •  孤独总比滥情好
    2021-01-23 18:28

    It's a question from a long time ago and I stumbled upon it as I was troubleshooting the very same issue - the solution was actually pretty silly and most probably was also the case - as it's a for loop it iterates through every list element, if even one of those elements doesn't fulfill the if condition, it will automatically trigger the else - pretty self-evident but easy to miss for beginners. Well at least that was the problem in my case :)

提交回复
热议问题