Learn String Manipulation by Building a Cipher - Step 39

Tell us what’s happening: lesson is asking the following: Now, instead of printing space! , use the addition assignment operator to add the space to the current value of encrypted_text .

i have added the
encrypted_text += " "
but am not sure why its throwing anerror
Describe your issue in detail here.

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 += ' '
    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/ Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 39

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hello bthomas,

You are indeed, literally, adding a space to encrypted_text right now. But look at the line above if char == ' ': you made an if statement to see if char is currently the space character.

So maybe instead of literally adding ' ' is there something else you could add to add a space to encrypted text?


Remember that char is taking the value of each character, including the space, in each iteration of the for loop.

Instead of hard coding a space use the value of char in that iteration. Is the same result; but the exercise expect you to handle the value of char in a particular case.

It should be MOD EDIT SOLUTION REMOVED. I think this is a good coding practice should in case the char value is changed.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Okay, thanks. I promise to act as stated.

can you explain what MOD is? I’m not really understanding the instructions. I’m stuck

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

MOD stands for moderator. Their post was removed because they provided the solution to the challenge which is not allowed on the forum so a moderator removed it

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.