STEP 8: The interval event will send cars down a random road infinitely! First let's choose the random road.

  • We need to replace the code in the event. Delete sprite.turn_left(15).
  • Go to the LOGIC tab and the toolkit. Drag Random Choice indented inside the event.

This code chooses a value randomly from my_list which contains y-coordinates.
Depending on which coordinate we choose randomly, we'll create and move a car left or right!

# 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(): sprite.turn_left(15) # add any other actions... stage.event_interval(interval, 0.5)