Learn String Manipulation by Building a Cipher - Step 30

Tell us what’s happening:

Instruction : At the end of your loop body, declare a variable called new_index and assign the value of index + shift to this variable.
Keeps showing error’ You should assign ‘index + shift’ to your new variable at the end of your ‘for’ loop body.’

Your code so far

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

for char in text.lower():
    index = alphabet[0]
    print(char, index)
    
    new_index = 'index + shift'


# User Editable Region

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

for char in text.lower():
    index = alphabet[0]
    print(char, index)
    
    new_index = 'index + shift'

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 30

Hello and welcome to the forum!

You almost have the solution, just don’t put the variable names in quotation marks.

This turns them in a string, while you are expected to store just the two variables into new_index.

Hi Daniel, thank you for the warm welcome and guidance. However, it still shows error message despite removing the quotation marks.


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

for char in text.lower():
    index = alphabet[0]
    print(char, index)

    new_index = index + shift

For future posts:

Please link to the task.
Please show your original code (follow the instructions under “help”).

In Python showing the original code is vital, since the language depends on indenting the code blocks into the right spots.

It’s impossible to see the way you are showing your code now if you have just a formatting error.

Thanks!

1 Like

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

1 Like

You can reset this step. What you’ve added is correct but you’ve changed some some of the other code now. Originally it had

index = alphabet.find(char)

but you’ve changed it to

index = alphabet[0]
1 Like

Thank you, will follow next time!

1 Like

That helped! Thank you =)

1 Like

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