Learn String Manipulation by Building a Cipher - Step 41

Tell us what’s happening:

i hv to compare char with an empty space using the equality operator inside dafor loop and im pretty sure thats what i have done here but it seems its wrong ig
not sure wht im doing wrong

Your code so far


# User Editable Region

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

for char in text.lower():
    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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 41

A string can either be empty or have a space inside of it. Which one do the instructions want?

it says with an “empty space”

pls helpp

im really stuck tho. idk wht else i shud do
pls help <3

That’s silly. There is no such thing as an empty space. Look at the string they gave you to use

At the beginning of your loop body, print the result of comparing char with an empty space (' ' ). Use the equality operator == for that.

copy pasted the exact instructions. “empty space”
plssssssssssss heelp

Yes. I’m still saying that there is no such thing as an ‘empty space’ in a string. Use the exact string they gave you

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

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

it doesnt work
and the instructions do say empty space so now im really confused
cud u like explain t0 me as to wht im doing wrong?

You aren’t using the string they gave you. There is no space between the quotes

Ignore the phrase ‘empty space’. It’s wrong

char == ('')

i hvnt added a space between quotes, ig the font makes it look like tht
and i tried it, buut it doesnt let me move on to the next step

There is no space between the quotation marks here. There must be a space between the quotation marks. Put a space in there like the string they gave you.

u just told me to add a space, but idk it doesnt work with or without spaces

char == ('  ')

char == (' ')

Show me the code with a space added. You haven’t shown any code with the space added.

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

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

There, now you’ve got the string correct. But you are missing the other part. You need to 'print the results.

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

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

doesnt work

Because you did not ‘print the result’. You ‘printed the char’. You need to print what happens when you compare the char with the string holding one space.

i dnt understand
how do i even do tht the instructions given r really not clear about this

This says, "compare char to a string with a single space, then throw away the result and ignore it’.

You need to print this instead.

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

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

i thught this was it
but apparently its not