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