Learning string manipulation by building a cypher step 30

#I have been looking at forums and reset this code few times already I cant get it to submit. Not sure what the issue is. Any help would be appreciated. Thanks

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

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

error
*Sorry, your code does not pass. You’re getting there.
You should assign index + shift to your new variable at the end of your for loop body.

I tried to print as
print(char, new_index) no good there either

Hello and welcome!

Just put the code into the last line.
The task literally wants you to place it at the end of the loop.

Thank you that did it. I dont know how that is body of “for” loop when its after print function. But it took it successful. Thank you for quick response

The body of the for loop is anything intended one level after the line for ending with colon. At the end of your for loop body, would be interpreted as after the for loop which means at the same level of indentation that the word for

1 Like

To elaborate on that, maybe you are thinking of a return statement. A print function can be placed anywhere in the code, it’s a popular debugging method in many languages.

1 Like

Thank you that helps a lot. I really need to learn this stuff

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 (').

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