Learn String Manipulation by Building a Cipher - Step 16

Hello, guys.
I had have followed the instructions in the exercise, but when I check the code the system print: You should assign the alphabet letter at the index index + shift to your new variable.

Tell us what’s happening:

Hello, guys.
I had have followed the instructions in the exercise, but when I check the code the system print: You should assign the alphabet letter at the index index + shift to your new variable…

Your code so far


/* User Editable Region */

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print (index)
shifted=index+shift
print(alphabet[shifted])

/* 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/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 16

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.

Hello Ante,

So the code you wrote now is theoretically not wrong. It does the same thing, and prints what you would expect.

Now the problem of why it not passes is, that the variable shifted needs to have the alphabet letter at index plus shift assigned to it. So instead of doing print(alphabet[shifted]) you need to change the variable assignment it so that if you print(shifted) it still works as intended.

1 Like

Thanks, for your help. But, I will try resolved it. For now, I believe that I must analyze it, because I don’t understand it.

I did this.

TEST No.1

text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
shifted = alphabet.find(text[0].lower())+shift
print (alphabet[shifted])

TEST No.2

text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
shifted = alphabet.find(text[0].lower())+shift
print (shifted)

Oh no we’re getting a bit off track. The only thing that we need to change is adding a new variable, we don’t want to remove any of the original variables.

So if we go back to the initial code:

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)

Now without removing anyting, on line 6 we’re going to declare a variable named shifted. What we need to assign to shifted is the alphabet letter at index plus shift .

You were really close with what you wrote originally alphabet[shifted] but since we’re doing it in the shifted assignment we can’t write shifted in the square brackets.
Instead you have to use index + shift.

Now if you done all correctly, if you print(shifted) it should show you k in the console under the 7 digit that was there already.

2 Likes

Mmmm… I am very slow. Thanks, for you help, HungryBee.

1 Like

No worries, slow or fast, as long as you keep learning you get where you want to be. Better to be slow and diligent than being fast and unmotivated. Plus the more you learn the easier it will get, as it will all start to make sense. :blush:

2 Likes

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