Learn String Manipulation by Building a Cipher - Step 42

Tell us what’s happening:

I’ve checked other questions but they don’t seem to be different to mine. What’s wrong with it?

Your code so far

# User Editable Region

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

for char in text.lower():
    if char == ' ':
    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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 OPR/ (Edition std-1)

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 42

What does the error message say? Where have you gotten stuck trying to fix it?

This doesn’t look like printing the result of comparing the char to a single space. You do the comparison, but you don’t actually print the result of the comparison itself.

What do you mean? Sorry for not understanding, but isn’t what I’m doing printing ‘space!’ if the result of the comparison is True?

Yes, you are printing “Space!”. You are not

print[ing] the result of comparing char with a space (' ').

Are you saying I should phrase it like this?

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

Closer, but you don’t need to guard the print statement with an if. Your second line, properly indented, is all you need.

Ah, thank you. I’ve got it working now. Thanks for helping me!

1 Like