Learn String Manipulation by Building a Cipher - Step 40

Tell us what’s happening:

text = ‘Hello World’
shift = 3
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
encrypted_text = ‘’
for char in text.lower():
if char == (’ '):
print (‘space!’)
index = alphabet.find(char)
new_index = index + shift
encrypted_text += alphabet[new_index]
print(‘char:’, char, ‘encrypted text:’, encrypted_text)

This is my code so far. shows correct but says does not pass.

Your code so far


# User Editable Region

text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in text.lower():
    if char == ('   '):
        print ('space!')
    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/129.0.0.0 Safari/537.36 Edg/129.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 40

This is not " print the result of comparing char with a space (' ')".

if character is blank to print space in the exercise. comparing char to a blank space the print space

char: h encrypted text: k
char: e encrypted text: kh
char: l encrypted text: kho
char: l encrypted text: khoo
char: o encrypted text: khoor
space!
char: encrypted text: khoorc
char: w encrypted text: khoorcz
char: o encrypted text: khoorczr
char: r encrypted text: khoorczru
char: l encrypted text: khoorczruo
char: d encrypted text: khoorczruog

That’s not what the instructions said. The instructions said to print the result of the comparison.

The result of a comparison will be True or False.

Also note:

'' empty string
' ' space
'   ' 3 spaces