DEBUGGING: Using input as a list index might result in an index that doesn't exist! We can fix that with modulo.

  • Click Run and enter a number that is greater than 7. What happens? Read the error message.
  • It says "index out of range" because the index is too large! The maximum index for color_list is 7.
  • Find the line where we first use index and change it to this: index = user_input % len(color_list)
  • Click Run again and enter any number greater than 7! What happens now?

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)