I have been having some issues with figuring this one out, and I think perhaps I’m just not understanding the question?
I’m under the impression that the value I’m looking for here is either 10 or k but I’m not having any luck. How exactly am I supposed to be declaring this new variable? Am I overthinking it by utilizing the same string of ‘index’ and then trying to add the other variable shift? Or is there something more complicated I’m not grasping.
Anyone willing to break it down and help further explain would be appreciated.
Thanks!
Your code so far
/* User Editable Region */
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index = alphabet.find(text[0].lower())
shifted = alphabet.find(text[0].lower()) + shift
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
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 16
On the right track. You don’t need to use find again though, you’ve already located the start position (index).
You just want to shift that up the alphabet by adding index + shift together. You want to access the letter in alphabet at index index + shift and store that in shifted
For example, you can access the letter in text at index 0 with text[0] and store that in a variable: variable = text[0]
find is a function or method and it takes arguments in parentheses.
But within that you can see text[0].
text[0] is not a function, but you are using the square brackets to access one element in that string, the first letter. This is used a lot to access 1 element of an object like a list. Either by index/position # or by name in an object.
You used alphabet.find() to use the find method to return the position of a character you were looking for, 7. Now you know where it is you can access it by index alphabet[7] which will return h.
You can also put any expression which will return a number in the brackets alphabet[7+1] etc.