Learn String Manipulation by Building a Cipher - Step 16

Tell us what’s happening:

it says that i should assign the alphabet letter at the index index + shift to your new variable but i still struggle with that. the task is :: 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


/* User Editable Region */

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
print(index)
shifted=""
print(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 Edg/120.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 16

Similar to how text[0] accesses the first (position 0) letter in the string text

text = 'Hello World'
print( text[0] )
>>> H

You’ll access the letter at position stored in the variables index + shift in the string alphabet and assign it to a variable called shifted

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

Use this syntax: variable = string[var1 + var2]

You have it started:

shifted=""

Delete the quotes and fill in the other variables.

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