Learn String Manipulation by Building a Cipher - Step 49

this is my code so far for step 49 but it says line 10 has a name not defined but i didnt make changes to anything except adding the def function

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 + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
print('plain text:', plaintext)
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/122.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

Welcome to the forum :wave:

Please share the line and the exact error, it’s hard to help without that. The error has important details. If you say “I have an error” the first question is “What is the error?”

Here is your line 10:

            index = alphabet.find(char)

Your error:

Traceback (most recent call last):
  File "main.py", line 10, in <module>
NameError: name 'alphabet' is not defined

But alphabet is defined right here, right?

alphabet = 'abcdefghijklmnopqrstuvwxyz'

But you have indentation problems:

These vertical lines will help you but you need to indent once for a new clause.
for on line 6 is not indented at all?

Read the last instruction again:

indent all the following lines to give your new function a body.

Are ALL the following lines indented?

when i make my indents the error reads the same saying alphabet is not defined on line 10

Then you’ve done it wrong. You should reset the step and try it again.

After typing “def caesar:” all you need to do is select all of the text after that and hit tab once.

This will indent everything 1 level to be inside the function.

i reset the step added my function and indented all below i think my original issue was not indenting the two print calls on the bottom my issue i resolved thank you.

1 Like

If you look at the indentation of the original code you’ve posted here, you’ll see it’s quite different.

1 Like