Learn String Manipulation by Building a Cipher - Step 29

Tell us what’s happening:

The confusing part for me is that when I added a new variable, “new_index,” it told me that I should declare it, and after I did it, it kept saying that I should declare “new_index” even though I already added it. Can someone help me with that?

Your code so far


# User Editable Region

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'

for char in text():
    index = alphabet.find(char)
    new_index = index + shift
    print(char, index)

# 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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 29

Hi, welcome to the forum :wave:

At the end of your loop body

Put it as the last line of code in the loop.

tried it and it did not work, the error is the same

my code’s example:

for char in text():
    index = alphabet.find(char)
    print(char, index)
    new_index = index + shift

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

You’ve changed the loop variable.

Reset the step and try it again.

Found the solution, thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.