Coded correspondance - modulus use

I just have a quick question about the first part of the coded correspondance activity.

How does the modulus function allow the computer to go to back to the beginning of the alphabet?

I will post the solution here for context:

translated_message += alphabet[(letter_value + 10) % 26]

Modulus is something that I have been struggling to understand

It basically supplies you with the remainder of division. How many times does 3 go into 10? Three whole times with a remainder of 1. 3 % 10 would provide you that remainding 1.

Using it as above it means you never exceeed the index of the list and isntead wind back up at 0. How many times does 26 go into 26. Once, zero remainder.

25 % 26 # Zero times, 25 remainder.
26 % 26 # Once, zero remainder.
27 % 26 # Once, one remainder.


Ah okay so the code would use the remainder value as the new letter value in that case to allow it to shift through the alphabet again?

Well there’s certainly a good way to find out. Try it and see. A few print statements or similar should provide you with the necessary output to determine what’s going on.