Learn String Manipulation by Building a Cipher - Step 40

Tell us what’s happening:

can’t figure out the problem to this question.

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)

Your code so far


# User Editable Region

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)
    

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

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 40

you are not comparing a space here, it is an empty string

so should it look like this:
char == ’ '? I tried it like this also but still got error.

post your updated code please

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)

I still do not see a space in there, there is nothing between the quotes

I’m not understanding.

you are writing '', see how there is a quote and immediately after an other quote? you need to have a space character in there between the quotes

ok so it should be quote then space and then another quote:
char == ' '

one single space, not more than one

if you still have issues please post your updated code

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)

on here it dosen’t look like I put space inbetween the quotes but I did. I did one quote, space then another quote,

and how many spaces did you put? only one? that does not look like only one

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

I ran the code and, in the console, it did the comparison

char: l encrypted text: kho
False
char: l encrypted text: khoo
False
char: o encrypted text: khoor
True
char:   encrypted text: khoorc
False
char: w encrypted text: khoorcz
False
char: o encrypted text: khoorczr
False
char: r encrypted text: khoorczru
False
char: l encrypted text: khoorczruo
False
char: d encrypted text: khoorczruog

but it still says something is wrong.

post your updated code please

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)

you have multiple spaces there

also remember what is the request for this step, what are you asked to add?

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

so it asks for a print to be at the beginning of your loop, it is not so in your code

2 Likes

thank you, overthinking the question. You gotta love programming.