Learn String Manipulation by Building a Cipher - Step 42

Tell us what’s happening:

I dont know what i’m doing wrong. I have read the forum and I think I understand the reasoning, but I still can’t get it right? Please help!! x

Your code so far


# User Editable Region

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

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 42

2 Likes

Hi

Can you say what your change to this line is doing to your code?

if char += ' ':
       
1 Like

You’re very close. Right now, you’re using char +=' ' is it correctly printing what’s needed? Good luck!

1 Like