Learn String Manipulation by Building a Cipher - Step 42

Tell us what’s happening:

I am getting so confused about this step. I think I am understanding what needs to be done but confused on how to put it. Anything will help.

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/127.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 42

Hi there,

This is the default code:

    if char == ' ':
        print('space!')

First of all, the instruction said:

Now, instead of printing 'space!',…

that means:

    if char == ' ':
        _put_your_code_here_

Secondly, what you did:

was using the addition assignment operator to add the current value of encrypted_text to the space ' '

while what we need to do is:

use the addition assignment operator to add the space to the current value of encrypted_text.

You got it backward.


And one more thing:

This statement we need to do to replace the print statement is one indentation level inside if char == ' ':, right?

That means it only happens when char is equal to ' '
That means, instead of using ' ' in our statement, you can use char

That’s what the instruction meant by:

the space (currently stored in char)

1 Like

thank you so much for your help!

2 Likes