Learn String Manipulation by Building a Cipher - Step 42

Tell us what’s happening:

I have followed the instructions and tried to run my code but it says syntax error when I add the += operator.

Your code so far


# User Editable Region

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

for char in text.lower():
    if char == ' ':
        print(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/124.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 42

Welcome to the forum @Andromeda-crypto

For this step, you need to remove the print call.

Now, instead of printing 'space!' , use the addition assignment operator to add the space (currently stored in char ) to the current value of encrypted_text .

Also, add char to encrypted_text, a certain order is required for the variables.

You should use the += operator to add char to the current value of encrypted_text inside your new if statement.

Use the addition assignment operator instead of the addition operator.

Happy coding

for char in text.lower():
if char == ’ ':
encrypted_text += char