Learn String Manipulation by Building a Cipher - Step 16

I got to this part but i can’t solve it. I did shifted = index + shift but it’s just giving me back an error. The challenge is " Declare a variable named shifted and assign it the alphabet letter at index plus shift."

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

Learn String Manipulation by Building a Cipher - Step 16

You are assigning the index plus shift, not the alphabet letter at that modified index.

1 Like

How do i do that? I don’t really understand it.

For example to get second letter from the text below, you’d use the 1 index:

text = 'string'
print(text[1])  # t

In the challenge similar thing needs to be done using the alphabet and the index that’s added value of index variable and value of shift variable.

I tried what I could think of trying but i’m still not getting it.

What’s your latest code?

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

I didn’t realize I’m using for the example variable name that’s present also in challenge, sorry about that.

Take a look at the:

shifted = text[0].lower() + shift

Specifically at shifted = text[0].

To use similar terms as in the challenge: to the shifted variable is assigned text letter at 0 index. Try to compare it with the instructions and figure out with what they should be replaced, to pass challenge.

1 Like

I did this: shifted = alphabet.find(text[7]) + shift but it still came back as wrong.

That’s a bit different than what is needed. The syntax that you need is basically: variable[wanted_index]

Hi, so i can’t solve this part either and i don’t really understand why…
Here it is:

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

It’s giving me a error message whereas, when i run it into python, it works…

2 Likes
alphabet[index+shift]

This looks better. What error message are you getting?

Well, I got an error telling me to create a variable named shifted… I tested it again and, surprise!: my program works and I passed the challenge so …

3 Likes

Yeah I think the key is that at first you were calling the location of index+shift in the text instead of the alphabet variable. At least it works now!

step 16: .find() returns the index of the matching character inside the string. If the character is not found, it returns -1. As you can see, the first character in text, uppercase 'H', is not found, since alphabet contains only lowercase letters.

You can transform a string into its lowercase equivalent with the .lower()
method. Add another print() call to print text.lower() and see the output.

index = alphabet.find(text[0].lower())
print(index)
shifted = alphabet[index+shift]

I didn’t understand where i go next. I’m entering it in wrong
please help

Hey @oliviabush18, for convenience please start new thread, including your current code.

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