Learn String Manipulation by Building a Cipher - Step 40

Tell us what’s happening:

something wrong? I guess char should go with some other element too?

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/127.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 40

You are trying to change char to be a double equals sign.

= this is the assignment operator, it assigns a new value to the variable on the left.
== this is the comparison operator, use it to check “are these two things equal?”

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

You will need to use print() here. Check if char is equal to a space, which is two quotes with 1 space between them ' '

1 Like

This is very close, but you are only printing char. The whole comparison needs to be within the print brackets in order to print it.

print(a) + b   # not valid 
print(a + b)   # print the result of a + b

I tried this but it still doesn’t corret something off the mark? print(char + ‘==’)

I tried this but it still doesn’t corret something off the mark? print(char + ‘==’)

print the result of comparing char with a space (' '). Use the equality operator == for that.

The instructions don’t mention anything about + or adding or concatenating anything. Don’t use + that was just my example. You only needed to adjust your brackets so the expression was fully inside the print() brackets.

1 Like

I tried this but it said char is not defined, should I put variable char first before the loop? char = ’ ’
my code:

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

Please open a new topic, thanks!

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like