Learn String Manipulation by Building a Cipher - Step 39

Tell us what’s happening:

How do I go about this step?

Your code so far

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

# User Editable Region

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)

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 39

You’ll notice that currently, in each iteration of your for loop you are setting the value of encrypted_text to a specific letter:
Untitled
Each iteration of the loop changes the value of encrypted_text to a different letter.

This step requires you to concatenate each letter onto encrypted_text, so that you will instead build up an encrypted string version of your original message.

Here’s an example of reassignment vs concatenation:

# reassignment
name = 'igor'
print(name) # igor
name = 'getmeabrain'
print(name) # getmeabrain

# concatenation
name = 'igor'
name = name + 'getmeabrain'
print(name) #igorgetmeabrain

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.