# User Editable Region
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
if char += 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 43
Good day
I’m experiencing a syntax error on my code, I di make use of the additional assignment to add the value of char . Kindly assit me with this issue.
I’m required to replace print space with the addition assignment so what I did inside the if statement I declared the variable of char of which i assigned the value of encrypted_text which is ’ ', yet I’m still getting an error, I might not have understood the question so could you kindly explain in a less technical way so that I can get a better understanding.
Warm Welcome There !
I think this is a less technical solution :
The if char += encrypted_text : line is invalid according to Python. This will throw a Syntax Error.
Because, first understand that a if condition works when something returns True. In your code’s if condition, nothing is returned as True or False. The Python’s += operator is a operator that does a built - in function operator thing. It does something, not checks something.
Change the if condition to a better way to check if there is a space (" ") there.
Thanking You. Reply if you still have doubt.