Learn String Manipulation by Building a Cipher - Step 16

Tell us what’s happening:

This is the explanation:

Step 16

As you can see from the output, "h" is at index 7 in the alphabet string. Now you need to find the letter at index 7 plus the value of shift. For that, you can use the addition operator, +, in the same way you would use it for a mathematical addition.

Declare a variable named shifted and assign it the alphabet letter at index plus shift.

Your code so far

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


# User Editable Region

The outcome is 'k', which I think is the right ('h' = 7, so 'k' = 10)

Why is my answer not accepted? Thanks for any help!

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

Hello Ludo,

The outcome is right, but the question wants shifted to be the alphabet letter at index + shift. Right now shifted is literally index + shift and then you print the alphabet letter that represents this.

Can you change this so that you can just print shifted and you still get the same outcome?

2 Likes

Ah I see! Thank you!

Changed it to this and now it worked:
SOLUTION REMOVED

2 Likes

Please don’t post solution code, thanks!

Roger that, my apologies!

2 Likes