Python if and elif conditional

  Kiến thức lập trình

I am not sure what is wrong with my code. when i implement everything with the elif and below
everything stops working. Self._defused wont work anymore and self._failed wont work either.

    def run(self):
            self._running = True
            while self._running:
                if self._value == self._target:
                    self._defused = True
                elif self._value != self._prev_value:
                    for i in range len(self._value):
                        if self._value[i] != self._target[i]:
                             self._failed = True    
                self._prev_value = self._value
            sleep(0.1)
        

This is a “defuse the bomb” project, and this is the toggles phase of the game. You flip the 4 toggles to represent a number in binary. toggle down = 0 up = 1. I can get it to defuse if i comment out the elif statment and below. Once I implement the elif and below I can no longer defuse it and the self._failed that calls a function to take a strike off the strike counter will not call either.

New contributor

Jacklan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT