I’ve tried everything I can think of and just can’t figure this out. It wants me to use the addition assignment operator to add the space (stored in char) to the current value of encrypted_text.
I tried changing line 4 to “encrypted_text += char” and got an error message. I tried putting it in line 8 instead, making sure to indent it four spaces. Error message.
What do I do? Could I just get a spoiler? The hints just aren’t doing it.
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] += char
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/120.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 43
nstead of printing 'space!', use the addition assignment operator to add the space (currently stored in char) to the current value of encrypted_text.
Line 8 is correct since you are replacing the print() line.
You should reset the lesson though, or change that line as @Teller suggests, because you’ve changed too many lines now. You can reset the step between each attempt.
You’re trying to use the addition assignment operator for the space character, but it should only be applied to the alphabet characters. To fix this, you can update your code in the 'if char == ’ ': ’ block to only include the space character without the addition assignment operator.