Learn String Manipulation by Building a Cipher - Step 49

Tell us what’s happening:

i done like what they instruct but why the indent error is occured …i dont really know how to clear the error and cant understand the hint it gives…i already used def keyword for create a function but it still says to mention def keyword…

please somebody helps me

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/132.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

Hi there and welcome to our community!

You shouldn’t indent the def caesar statement, only the code which follows it.

It’s an error on their part. The UI is checking for an indentation after “shift = 3” instead of after “def caesar():”. Even if the code is correct, it’ll still give an error because it’s mindlessly looking for indentation after the wrong line of text. Programs do exactly what we tell them to do even if it’s the wrong thing to do. And I heard that 41% of AI generated code has errors. Don’t think we’re in danger of being replaced by AI any time soon. Whoever the code monkey is that has it looking for indentation after the wrong line should be replaced.

Here’s the rest of a bug report I wrote up but apparently can’t directly submit:

The indentation should follow “def caesar():” not “shift = 3”, which is likely the cause of the error. I’ve tried indenting it anyway and it still gave me errors. Even if “shift = 3” were made part of the caesar function, it’s still asking to indent following that specific text. Written correctly the program would work fine, but the interface will still give an error because it starts looking for an indent where there shouldn’t be one.

The compiler is also telling me on line 15, in , NameError: name ‘encrypted_text’ is not defined, when it clearly is in the two lines following the function declaration, and yes I checked my spelling several times. EE en see arr y pee tee ed.

def caesar():
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
encrypted_text = ‘’
(note that the forums remove the empty space indents so it looks like I didn’t indent this example)

Declaring the variable at the top, right after text = ‘Hello Zaira’, clears up this error, but the error to indent after shift = 3 remains.

And as evidence I’m not a complete idiot, how much so depending on how much sleep I’ve gotten, I’ve completed SoloLearn’s Introduction to Python, Intermediate Python, and Introduction to C++ (but I have to rant that I think they intentionally create errors and ask questions about things they haven’t defined yet to cost you hearts to push you to pay for premium). As well as Introduction to Programming with Python on Alison which was done by Sal of Khan Academy, and read Severence’s book.

Please open a new thread for your question. You’ve just repeated what was already said succinctly in the previous comment.

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge. This button only appears if you have tried to submit an answer at least three times.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.