Else statement executing even the IF statement is TRUE

后端 未结 4 1715
醉酒成梦
醉酒成梦 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:34

    Next solution fixed my problem:

        for slovo in slova:
            if pygame.mouse.get_pressed()[0] and slovo["rect"].collidepoint(pygame.mouse.get_pos()):
                xy = 0
                for i in range (len(randRijec)):
                    if slovo["name"] in randRijec[i]:
                        xy = 1
                        if i == 0:
                            slovo1 = randRijec[i].upper()
                            prvoSlovo = 1
                            break
                        if i == 1:
                            slovo2 = randRijec[i].upper()
                            drugoSlovo = 1
                            break
                slova.remove(slovo)
                if xy == 0:
                    pogresnoBrojac += 1
    
        ...
        ...
        ...
    
        xy = 1
        pygame.display.update()
        time.tick(value)
    

    So, I have just added that xy counter that makes my code work how it should work. When IF statement is met, xy becomes 1, if IF statement isn't fulfilled, xy is set to 0 and then this "else" statement executes. At the end of the code, xy is set to 1 again to prevent executing this "else" (if xy == 0) block.

提交回复
热议问题