Learn String Manipulation by Building a Cipher - Step 26

Tell us what’s happening:

what do I have to do to get it done?
Step 26
Inside the for loop, before printing the current character, declare a variable called index and assign the value returned by alphabet. find(char) to this variable.

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(char)
index for (char)  in text:
print(char)

Your code so far


# User Editable Region

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(char)
index for (char)  in text:
print(char)

# 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/133.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 26

Hello and welcome to the forum :wave:

#this is before the for loop
for this in that:
    #this is inside the for loop

#this is after the for loop

Watch your indentation. Code in the for loop must be indented.

text = 'Hello World'

shift = 3

alphabet = 'abcdefghijklmnopqrstuvwxyz'

index = alphabet.find(char)

for (index = alphabet.find(char)) in text:

print(char)

still error

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 doesn’t look quite right. Reset the step and try again.

You should be adding 1 new line of code and changing nothing else.

Remember about indentation.

text = ‘Hello World’

shift = 3

alphabet = ‘abcdefghijklmnopqrstuvwxyz’

for index = alphabet.find(char) in text:

print(char)

i still dont understand where I should have to add new line of code

text = 'Hello World'

shift = 3

alphabet = 'abcdefghijklmnopqrstuvwxyz'

for char in text:

index = alphabet.find(char)

print(char)

This is correct.

I’m not sure if the indentation was lost when you pasted this into the forum? Usually it’s ok which means your indentation is wrong.

code
code
#this is before the for loop
for this in that:
    code
    #this is inside the for loop
    code

#this is after the for loop
code
code

Indentation MUST look like this.

1 Like