Learn String Manipulation by Building a Cipher - Step 49

Tell us what’s happening:

I have indented everything and it still gives me as a feedback that the def keyword is not declared

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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

Welcome to the forum @klblasini5

Indent by a multiple of 4 spaces.

n

The vertical line shows where you have an extra space.
The print calls are not indented.

Happy coding

i don’t understand the solution here? i tried what you said and it still does not work.

Please share your updated code

Tell us what’s happening:

I tried fixing the indentation still didn’t work. the feedback I got feedback from someone on the forum and that didn’t help. I really don’t see the problem in my coding

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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

“all the following lines” means all of them, your for loop and everything after it is outside the function, while you should have everything inside the function

I have merged your two topics, please do not create multiple topics for the same challenge

Sorry i don’t understand what you mean

your for loop isnt indented like it should be

removed

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

I have worked on this already 1 hundred times and it keeps telling me the same tips that which i already corrected.

Please share your updated code

Maybe this will help. This is what it looks like to format your code by indenting it into a function:

code = code
code
code
def function:
    code
    code
    if this == that:
        code
    else:
        code
        code
    code
    code

EVERYTHING gets indented 4 more spaces. You were quite close before, you just missed some lines. The indentation needs to be exactly correct for every single line or it will not work.

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

Here I’ve indicated ALL the following lines. The last two print lines will also be part of the function and need to be indented.

I hope this helps!