Learn String Manipulation by Building a Cipher - Step 39

Tell us what’s happening:

Describe your issue in detail here.
not sure exactly where to place the addition assignment operator

Your code so far

``````
/* User Editable Region */

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

for char in text.lower():
if 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36`

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 39

Hi @moh_alkukhun! Welcome to the freeCodeCamp forum.

It looks like you have removed the line of `print('space!')`. Now, replacing that code, you need to write a code to add the space to the current value of `encrypted_text`.

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

for char in text.lower():
if char == ' ':
// write a code here to add the space to the current value of encrypted_text
index = alphabet.find(char)
new_index = index + shift
encrypted_text += alphabet[new_index]
print('char:', char, 'encrypted text:', encrypted_text)
``````

You will need to use the addition assignment operator (`+=`) in that line.

This line below may give you a hint on how to use it:

``````encrypted_text += alphabet[new_index]
``````
1 Like

can i have another hint
i tried — encrypted_text += " " —
but is wrong

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

I also tried with:
encrypted += ’ ’
but it works with:
encrypted += char

If `char==' '`,

``````+= ' '
``````

is equivalent to

``````+= char
``````

But the latter is deemed the correct one, apparently for using the same line for cases of other non-letter characters later.

Exactly, both answers are similar. But in this case, the “correct” answer is += char because we use the same variable (char) that we created in the for loop to iterate over each character of the text. In short, for order and coherence.

1 Like