Learn String Manipulation by Building a Cipher - Step 49

Tell us what’s happening:

I don’t understand why it doesn’t work. Can someone help me, please ?
I’ve done this:
text = ‘Hello Zaira’
shift = 3
def caesar():
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
encrypted_text = ‘’

for char in text.lower():
if char == ’ ':
encrypted_text += char
else:
index = alphabet.find(char)
new_index = (index + shift) % len(alphabet)
encrypted_text += alphabet[new_index]
print(‘plain text:’, text)
print(‘encrypted text:’, encrypted_text)

Your code so far


# User Editable Region

text = 'Hello Zaira'
shift = 3
def caesar():
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

for char in text.lower():
    if char == ' ':
        encrypted_text += char
    else:
        index = alphabet.find(char)
        new_index = (index + shift) % len(alphabet)
        encrypted_text += alphabet[new_index]
print('plain text:', text)
print('encrypted text:', encrypted_text)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

Welcome to the forum @C0STTER

Right after your shift variable, declare a function called caesar and indent all the following lines to give your new function a body.

You need to indent the rest of the code by four spaces.

Happy coding

It’s not that. It is telling me that the name ‘alphabet’ is not defined.

So the forum can assist please post your full code.

Use the following method to post code to the forum:

  1. On a separate line type three back ticks.
  2. On a separate line paste your code.
  3. On the last line type three back ticks. Here is a single back tick `

Happy coding