Learn String Manipulation by Building a Cipher - Step 41

Tell us what’s happening:

im getting following error , i tried various methods but I somehow cant find the solution.

// running tests
You should compare char with a space using the equality operator inside your for loop.
You should print the result of comparing char with a space inside your for loop.
You should print the result of comparing char with a space at the beginning of your loop.
// tests completed

Your code so far


# User Editable Region

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


for char in text.lower():
    print('char' +'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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 41

you need to compare char, the variable, so without quotes
you need to compare it using the equality operator ==
you need to compare it with a space

thank you for the reply, do you mean like this :
char == char

no, you need to compare with something different from itself, otherwise the comparison doesn’t make sense. One member of the comparison is char, which you did correctly, now you need to have the other member of the comparison a string that contains only a space

I see thanks , i did it like this: char == ’ ’
doesnt work but must be right?

Mind that there should be a space within the single quotes.

char == ' '

I did that but its not working , I am still receiving the same error

It is better if you show the modified code.

there is a space between but here its kinda not working.

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)

Consider that the request is asking something concrete:

At the beginning of your loop body, print the result

You need to write a print call adding what you found out about comparing the char as an argument to it.

print(...)

By the way, you must pay closer attention to detail, otherwise programming might become frustrating.

char == (’ ')

Is not the same than:

char == ' '
1 Like

I just cant find out what I should print, the console output is not changing

Example:

Print the result of comparing x with y

Solution:

print(x == y)

thank you so much, im trying my best to learn it even though its frustrating at my beginnning