STEP 2: Let's create a loop to replace all of this inefficient code!

  • Delete all the code after the second comment.
  • In LOGIC, drag out Loop with Range. Change the range() to 9 so the loop runs 9 times.
  • Move the code that is between the comments into the loop instead! The commands should be indented once.

You've refactored the code! Notice that the outcome is the same, but the code is much and more efficient.

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

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)