Learn String Manipulation by Building a Cipher - Step 42

Tell us what’s happening:

i don’t understand why i’ve written it but it still says that the code doesn’t pass

Your code so far


# User Editable Region

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''

for char in text.lower():
    if char == ' ':
        char += encrypted_text
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)

# 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/126.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 42

Hi there and welcome to our community!

This is back-to-front. You should be concatenating char onto encrypted_text, but you are concatenating encrypted_text onto char.

1 Like

hello, thank you!

i see. so apparently the order of how i write the code matters. thank you so much for the help!

1 Like

Well, yes that’s true, but in this case it’s because you are concatenating strings.

1+2 is the same as 2+1 but:

“week” + “end” is “weekend”
“end” + “week” is “endweek”

1 Like