STEP 9: Every time the user presses the spacebar, the pen should switch to a randomly chosen color.

  • In GRAPHICS, Click and drag Space Bar into the very bottom of your program.
  • Find and delete the line that says ····sprite.jump(5)¬
  • Click the LOGIC tab in the toolkit, then click .
  • Drag out Random Choice and drop it indented just under def·space_bar():¬

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_background_color("black") # sprite = codesters.Point(x, y) sprite = codesters.Point(50, 100) sprite.set_color("green") sprite.pen_down() def right_key(): sprite.move_right(20) # add other actions... stage.event_key("right", right_key) def left_key(): sprite.move_left(20) # add other actions... stage.event_key("left", left_key) def up_key(): sprite.move_up(20) # add other actions... stage.event_key("up", up_key) def down_key(): sprite.move_down(20) # add other actions... stage.event_key("down", down_key) my_list = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)