Learn String Manipulation by Building a Cipher - Step 42

Tell us what’s happening:

How can I solve this error code?, I add encrypted_text ready but code cannot run.

Your code so far


# User Editable Region

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

for char in text.lower():
    if char == ' ':
       print( ' ' += 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/605.1.15 (KHTML, like Gecko) Version/18.4 Safari/605.1.15

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 42

Addition assignment operator cannot be used in that place. If you remove the ' ' += encrypted_text from inside of the print() call, you also will get error though. Take a closer look at it, are you trying to add encrypted_text to the ' ' or ' ' to the encrypted_text?