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
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.
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