Learn String Manipulation by Building a Cipher - Step 50

Tell us what’s happening:

Describe your issue in detail here.
Each correction suggested that I indent my code after the “shift=3” line… And I’ve gotten this following error regardless of what is done…
“You should use the def keyword to declare a new function”

There are no other clear suggestions. I’m also unclear whether the “Reset” button would reset this individual lesson or the entire unit. The directions are unclear and this process is tedious without the final example available. I set the function up and didn’t pass in any parameters because I wasn’t instructed to.

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 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 50

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

I added the following text in the head to the post where is says to “Describe your issue in detail here.”
Each correction suggested that I indent my code after the “shift=3” line… And I’ve gotten this following error regardless of what is done…
“You should use the def keyword to declare a new function”

There are no other clear suggestions. I’m also unclear whether the “Reset” button would reset this individual lesson or the entire unit. The directions are unclear and this process is tedious without the final example available. I set the function up and didn’t pass in any parameters because I wasn’t instructed to.

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Please reference the above post… This appears to be generated each time I submit an entry to this forum page.

I copy and pasted the code from the next lesson and it appeared to work… The code block started on line 2 and the indentation was opposite the instructions I was given to indent everything after the “shift=3” line…

Solution code removed

declare a function called caesar and indent all the following lines to give your new function a body.

Indent all the lines following the function declaration.

Glad you figured it out, although I’m not sure I recommend that method. You are better off to read about indentation in Python or function declarations.

Please don’t post solution code, thanks!

https://www.w3schools.com/python/gloss_python_indentation.asp

https://www.geeksforgeeks.org/indentation-in-python/

https://www.w3schools.com/python/python_functions.asp

https://www.geeksforgeeks.org/python-functions/

please tell me what is the problem here

i was also stuck on this one for a few good 15mins, im pretty sure in previous lessons we were told that 4 spaces is the default number (and python adds this space automatically when you press enter), but for some reason on this one 1 space was enough, i dont know if this was supposed to be like this or not, since the default is 4 but we can also use only 1 based on their website where they mention: “Note: Python uses 4 spaces as indentation by default. However, the number of spaces is up to you, but a minimum of 1 space has to be used.”.

Please open a new topic for your question, thanks!