WARNING: This program has a bug, which means we need to fix it! This bug is a logic error.

RULE: An if-statement indented inside a previous if-statement will only be checked if the outer if-statement is true. If we want each if-statement to be checked, they must NOT be indented within each other!

  • Click Run and click the stage several times. If the triangle says 2, it should flip and turn red!
  • Fix the second if-statement so it is only indented once (line 12) within the event and indent lines 13-14 twice.

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

# sprite = codesters.Triangle(x, y, size, "color") sprite = codesters.Triangle(0, 0, 200, "blue") def click(): random_number = random.randint(1, 2) sprite.say(random_number, .5) if random_number == 1: sprite.set_rotation(0) sprite.set_color("blue") if random_number == 2: sprite.set_rotation(180) sprite.set_color("red") stage.event_click(click)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)