Learn String Manipulation by Building a Cipher - Step 27

Tell us what’s happening:

Not sure how to use bracket notation to access the first letter in text and try to change it into a character of your choice.

Your code so far


/* User Editable Region */

text = 'Hello World'
text = 'X' + text[1:]


/* User Editable Region */

shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'

for char in text.lower():
    index = alphabet.find(char)
    print(char, index)
    new_index = index + shift

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 27

Hello Binarycoder,

This one was a bit tricky, it’s trying to make you do something that isn’t possible on purpose.

So to access the first character of a string you can use string_var[0]. So in this case it would be text[0].

Now comes the tricky part though, normally to assign a variable you would just do variable = "something". It wants you try and do something similar with the first letter of text so you learn that you aren’t able to do so.

If you’re still stuck, you will see the answer here:

Answer
text = 'Hello World'
text[0] = 'x'
1 Like

You are amazing, thank you! :")

1 Like

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