Learn String Manipulation by Building a Cipher - Step 16

Tell us what’s happening:

I need to declare a variable named shifted and assign it the alphabet letter at index plus shift. I’m not sure how to incorporate the alphabet letter.

Your code so far


/* User Editable Region */

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

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 16

1 Like

Use the same method you used to get the first letter of the text string here.

2 Likes

@r2brzckbw7 , the idea is the same with what we did to line index = alphabet.find(text[0].lower()) specifically text[0].

text = variable for ‘Hello World’
[0] = index 0 to get the first character ‘H’

use this for the alphabet variable. hope this helps

1 Like

i don’t understand sir

1 Like

I still don’t understand this. What exactly is it that I’m looking for? Am i looking for what the 10th character is in ‘Hello World’, because it’s asking me to add index to shift, thus shifting the 7th character 3 spaces to find the 10th character? But there isn’t 10 characters in that variable. So am I looking for the 10th character in ‘abcdefghijklmnopqrstuvwxyz’?

I wrote this:

text = ‘Hello World’

shift = 3

alphabet = ‘abcdefghijklmnopqrstuvwxyz’

index = alphabet.find(text[0].lower())

print(index)

shifted = index(text[7]) + shift()

But i still got the wrong answer.

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

The goal is to shift each letter of the word a certain number (shift) of letters down the alphabet. H is the 7th letter of the alphabet so index = 7.

You want to take index and add shift.

index + shift.

Then you assign that to shifted. So shifted would be 7+3 = 10.

Then eventually you will replace the H with the 10th letter of the alphabet. How will you find the 10th letter of the alphabet?

alphabet[10]

But use variables, don’t write “10” in there. and dont write “7” because it’s already in the variable index

If you have more questions about this please open a new topic (“Ask for Help” button)

1 Like

While I understand the rationale of what you’ve just explained, I am still struggling to figure out what the right code is to get the expected answer.

1 Like

Use the “ask for help” button and ask a question in a new topic.

Provide some information,
your current code,
what you’ve tried,
any questions you have,
any errors you’ve received.

This topic has already been solved so I’m not really sure what your specific question is.

MOD EDIT SOLUTION REMOVED

for those who are still struggling thats the answer

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.