Learn String Manipulation by Building a Cipher - Step 47

Tell us what’s happening:

This is my code. I dont know how to print what Im supposed to do with this. How do I print after the for loop?
text = ‘Hello Zaira’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
encrypted_text = ‘’

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

Your code so far


# User Editable Region

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

for char in text.lower():
    if char == ' ':
        encrypted_text += char
    else:
        index = alphabet.find(char)
        new_index = (index + shift) % len(alphabet)
        encrypted_text += alphabet[new_index]
    print('char:', char,)
    print('encrypted text:', encrypted_text)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 47

Hi there, welcome to fcc community.

Look at the indentation level of the print statement.
It’s still one level inside the for loop, that means the print statement is inside the for loop.

To make the print statement executed after the for loop is finished, you must put the print statement on the same indentation level as the for loop.

2 Likes

Thank you. I didn`t think to do that. Have to remember the indentions are automatic and I can alter that.