STEP 9: Two roads go left and two go right! We need to check with road we've chosen randomly to know.

A conditional, or if statement, sets up actions that will only happen if something is true.

  • From the toolkit, drag out if or so that it is indented one time inside the interval event.
  • Change both choice variables to my_var. Change "yes" to -150 and change "y" to 50.
  • In GRAPHICS and , drag Car 1 inside the if statement. Make sure it is indented two times!

# sprite = codesters.Rectangle(x, y, width, height, "color") start = codesters.Rectangle(0, -250, 500, 50, "red") # sprite = codesters.Rectangle(x, y, width, height, "color") finish = codesters.Rectangle(0, 250, 500, 50, "green") my_list = [-150, -50, 50, 150] for value in my_list: pass # delete after adding indented code # add code here # sprite = codesters.Rectangle(x, y, width, height, "color") sprite = codesters.Rectangle(0, value, 500, 50, "gray") # sprite = codesters.Sprite("image", x, y) sprite = codesters.Sprite("turtle1", 0, -240) sprite.set_size(.2) sprite.turn_left(90) def interval(): my_var = random.choice(my_list) stage.event_interval(interval, 0.5)