STEP 9: What happens if our shift is longer than the alphabet? Let's make it so that this can't happen!

Modulo is a math operator that results in the remainder of division. For example, 5 % 2 is equal to 1.

  • Edit the last line of code that you added to look like this: shift_index = (alpha_index + key) % 26
  • Using modulo gives us the correct shift even with large numbers. It divides the large number by 26 until it can't divide evenly anymore. The remainder of the division is our shift_index!

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)