Project 4: Caesar cipher
In his secret letters, Julius Caesar would shift each letter a few steps along the alphabet: a → b, b → c… An enemy couldn’t read it, but friends knew the secret. This is one of history’s first ciphers — and you’re about to write it.
How it works
Section titled “How it works”Keep the alphabet as text: alphabet = "abcdefghijklmnopqrstuvwxyz". .index() finds each letter’s position, and +1 shifts it:
alphabet.index("s")→18, so its cipher isalphabet[19]→"t"- The trap: shifting
"z"(index 25) gives 26 — there’s no such index! The fix:% 26closes the circle:26 % 26 = 0→"a". (Module 01’s%becomes the hero here!)
- Build the
alphabettext - Get the word with
input(), start with an emptycipher = "" for letter in word:— for each letter:pos = alphabet.index(letter)cipher = cipher + alphabet[(pos + 1) % 26]
- Print the cipher
Mission
Section titled “Mission”Caesar cipher
+30 XP ✓ CompletedFollow the plan and finish the encoder. (The input is hello — its cipher should be ifmmp.) Then send a friend a secret message, and figure out the decoding rule too: just shift in the opposite direction. 🕵️
Inputs (for input())
One value per line — read in order by input().
🏆 Congratulations — you finished the course! You wrote four real projects and earned the “Python Explorer” badge. What’s next? Write your own idea — that’s the best way to learn. If you have questions, get in touch. Good luck, programmer! 🐍