O
O
OccamaRazor2017-03-12 13:36:02
Python
OccamaRazor, 2017-03-12 13:36:02

How to create a loop in which the value of the second if will be executed only if the first if is executed?

That is, I want the second condition to be fulfilled only if the green light is on, that is, a green square is displayed, otherwise it does not work. I can’t do it yet, everything in the loop returns as it was and the second condition does not make sense, after the first Disabled = False, the False-True loop goes on and everything goes around, as a result, it works as it should for the first time and then True all the time

Disabled = False
  for car in cars:
                    if Disabled == False and (car.rect.y+75) == y :
                        pygame.draw.rect(DISPLAY, GREEN, 10,40)
                        Disabled = True
                    elif Disabled == True and (car.rect.y+75)+100 == y :
                        car.rect.y += 75
                        Disabled = False

Answer the question

In order to leave comments, you need to log in

3 answer(s)
U
User23, 2017-03-12
@User23

a = 0
for value in var:
    if asdf<zxcv:
        a = 1
    if a:
        #you code

T
tester_toster, 2017-03-12
@tester_toster

I am not familiar with Python, unfortunately, but in any language it is done like this:

while(){
   if(Условие 1){
      if(Условие 2){
      }
   }
}

F
fdrwitch, 2017-03-12
@fdrwitch

1. it is impossible to work with one bull-expressin 2 times in one if-e!!!!! (elif will never work)
2. after the first if, do the second full (as you were told)
a = 1
if a:
\t some code
\ta = 0
if a == 0:
\t some other code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question