Learn String Manipulation by Building a Cipher - Step 43

Tell us what’s happening:

To fix it, add an else clause after encrypted_text += char and indent all the subsequent lines of code except the print() call.
text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
encrypted_text = ‘’

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

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
   else:
       index = alphabet.find(char)
       new_index = index + shift
       encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)

I am confused because I added the indents

I added the indents and it’s not letting me trough what am I doing wrong?

Welcome to the forum @ameliaverdibello88

The Traceback is throwing an error for the else statement.
Try adding a single space before it, so it aligns with the if statement.

Happy coding