Coding for Kids · Lesson

Encoding a Message

Turn text into code.

Lesson 3 of 413 steps

Encoding a Message is a free Coding for Kids lesson on CoddyKit. This is lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Coding for Kids learning path, and your progress syncs across the web and the CoddyKit app. The Coding for Kids course includes 4 lessons in total.

Encode a Message! 📨

Now let's turn a whole secret message into code! 🔐 We'll shift every letter using our cipher.

Our Message 📝

Start with a message to hide.

message = 'HIDE'
print('Secret message:', message)

Pick the Key 🗝️

Choose a shift key. Keep it secret — only your friend should know it!

shift = 3
print('Shift key:', shift)

An Empty Box 📦

Make an empty string to collect the coded letters.

coded = ''
print('Start:', coded)

Loop and Shift 🔂

Go through each letter, shift it, and add it to the box!

message = 'HIDE'
shift = 3
coded = ''
for letter in message:
    coded += chr(ord(letter) + shift)
print(coded)

Try a Longer Message 📜

Encode a bigger word! Spaces will shift too — that's okay for now.

message = 'SECRET'
shift = 2
coded = ''
for letter in message:
    coded += chr(ord(letter) + shift)
print(coded)

Make It a Tool 🛠️

Wrap the encoder in a function so you can reuse it!

def encode(message, shift):
    coded = ''
    for letter in message:
        coded += chr(ord(letter) + shift)
    return coded
print(encode('HI', 3))

Encode Many Words 🔁

With the tool, encode lots of words easily!

def encode(message, shift):
    coded = ''
    for letter in message:
        coded += chr(ord(letter) + shift)
    return coded
print(encode('CAT', 1))
print(encode('DOG', 1))

Change the Key 🎚️

A different key gives a totally different code!

def encode(message, shift):
    coded = ''
    for letter in message:
        coded += chr(ord(letter) + shift)
    return coded
print(encode('SPY', 5))

Send to a Friend 📬

Show the secret message ready to send!

def encode(message, shift):
    coded = ''
    for letter in message:
        coded += chr(ord(letter) + shift)
    return coded
print('Send this:', encode('MEET', 4))

Your Secret Word 🤫

Encode your own secret word and a key only YOU know!

def encode(message, shift):
    coded = ''
    for letter in message:
        coded += chr(ord(letter) + shift)
    return coded
print(encode('PIZZA', 3))

Quick Check ✅

Why do we start with an empty string coded = ''?

Encoder Expert! 🏆

Fantastic! You learned to:

  • Loop through a whole message 🔂
  • Build a coded string letter by letter 🧩
  • Wrap it in a reusable function 🛠️
  • Change the key for new codes 🗝️

Next: decode a message back to normal! 🔓

Free to start

Learn Python with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
35
Lessons
140

Frequently Asked Questions

Is the “Encoding a Message” lesson free?

Yes — the full text of “Encoding a Message” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Coding for Kids course, upgrade to CoddyKit PRO. The Coding for Kids course includes 4 lessons in total.

What will I learn in “Encoding a Message”?

Turn text into code. You practise Coding for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Coding for Kids?

No prior experience is required. Coding for Kids on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Encoding a Message” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Coding for Kids lesson?

Yes. Every Coding for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Is a Code?
  2. Shifting Letters
  3. Encoding a Message
  4. Decoding a Message
← Back to Coding for Kids