Learn String Manipulation by Building a Cipher - Step 38

Tell us what’s happening:

Hi there!
I am stuck at step 38. Just couldn’t figure out how to do it, how to replace a variable with a new one, one that variable was already assigned a value of ‘’??. I really wanted to skip it, but didn’t know how either. Please help.

Your code so far


# User Editable Region

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

for char in text.lower():
    index = alphabet.find(char)    
    new_index = index + shift
    new_char = alphabet[new_index]
    encrypted_text = new_char
    print('char:', char, 'new char:', new_char)

# 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/124.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 38

Hey, you need to change new_char into encrypted_text. You don’t have to write additional lines of code. Simply modify the existing ones.

1 Like

Appreciate your response. However. I did not know how to do that.
I wrote encrypted_text = new_char , but did not work. In order to change a variable, you either delete it and type the new one or assign it to a new variable, according to my very humble understanding. So which one is relevant here?

You need to go to the line that you already have and change the name of the variable. You’re overthinking.

variable_name = xnew_name = x

Maybe I am, but my guess I am a bit SLOW at this point.
So, should I replace the name and preserve the same value, i.e. encrypted_text = alphabet[new_index], OR encrypted_text = new_char, OR encrypted_text =“”?

You should replace the name and keep the value. Also, after that you’ll need to change the print() call because you won’t have new_char declared anymore.

1 Like

Thank you so much. It was really simple; committing more than one minute mistake will get you in circles by fixing one and leaving the other interchangeably. Your advice and reassurance were much needed. Thanks.

1 Like